0

オペレーターオーバーロードの世界に足を踏み入れています。Vector2クラスで演算子のオーバーロードを実行することですでにある程度の成功を収めています。現在、Matrixクラスで作業しており、2つの行列を1つの新しい行列に追加する関数を作成しようとしています。私はこのエラーに遭遇していますが、グーグルで検索しても、人々はまったく異なる問題を抱えているように見えますが、同じ問題を抱えているため、それ以上のことはできません。

クラス宣言は次のとおりです。

Matrix.h

#ifndef __MAGE2D_MATRIX_H
#define __MAGE2D_MATRIX_H

namespace Mage {
    template<class T>
    class Matrix {
    public:
        Matrix();
        Matrix(unsigned int, unsigned int);
        ~Matrix();

        unsigned int getColumns();
        unsigned int getRows();

        T&       operator[](unsigned int);
        const T& operator[](unsigned int) const;
        Matrix operator+(const Matrix&);
        Matrix operator-(const Matrix&);

    private:
        unsigned int rows;
        unsigned int columns;
        T*           matrix;
    };
}

#endif // __MAGE2D_MATRIX_H

そして、これが機能していない問題のある関数です(これらはmatrix.cppの31行目から45行目です):

matrix.cpp

template<class T>
Matrix Matrix<T>::operator+(const Matrix<T>& A) {
    if ((rows == A.getRows()) && (columns == A.getColumns())) {
        Matrix<T> B = Matrix<T>(rows, columns);
        for (unsigned int i = 0; i <= rows; ++i) {
            for (unsigned int j = 0; i <= columns; ++i) {
                B[i][j] = matrix[i][j] + A[i][j];
            }
        }

        return B;
    }

    return NULL;
}

そして最後になりましたが、ここに私が得ている2つのエラーがあります。

1>ClCompile:
1>  matrix.cpp
1>src\matrix.cpp(32): error C2955: 'Mage::Matrix' : use of class template requires template argument list
1>          C:\Users\Jesse\documents\visual studio 2010\Projects\Mage2D\Mage2D\include\Mage2D/Math/Matrix.h(6) : see declaration of 'Mage::Matrix'
1>src\matrix.cpp(47): error C2244: 'Mage::Matrix<T>::operator +' : unable to match function definition to an existing declaration
1>          C:\Users\Jesse\documents\visual studio 2010\Projects\Mage2D\Mage2D\include\Mage2D/Math/Matrix.h(17) : see declaration of 'Mage::Matrix<T>::operator +'
1>          definition
1>          'Mage::Matrix Mage::Matrix<T>::operator +(const Mage::Matrix<T> &)'
1>          existing declarations
1>          'Mage::Matrix<T> Mage::Matrix<T>::operator +(const Mage::Matrix<T> &)'
1>
1>Build FAILED.

誰かがここで何が起こっているのか考えていますか?それはおそらく本当に簡単で、私は気が狂っています。コーヒーが必要です:|

心から、

ジェシー

4

1 に答える 1

1

'Mage :: Matrix':クラステンプレートの使用にはテンプレート引数リストが必要です

operator +の定義では:

 template<class T>
 Matrix<T> Matrix<T>::operator+(const Matrix<T>& A)
        ^
于 2012-09-16T11:42:10.707 に答える