带指针的C++动态二维数组(矩阵)

edu*_*222 0 c++ pointers operator-overloading matrix

大家:

我创建了一个程序,能够创建矩阵,并在学校的课程上执行各种操作.它们要求我们使用适当的Matrix操作使操作员超载.

我正在努力完成以下功能:

typedef double matrixType;


using namespace std;


class Matrix{
protected:
    int m,n; // m:row size n:column size
    matrixType **a; //Allows us to acces the a(ij) i,j position of the matrix


//==================================================
// (==Operator)Verifies if two given Matrices are equal
//==================================================

bool Matrix::operator==(const Matrix &B){

bool flag=false;


if(B.m ==m && B.n ==n){

    for (int row=0; row<m; row++) {
        for (int col=0; col<n; col++) {
            if (B[row][col] != a[row][col]) {
                flag=false;
            }
        }
    }
    flag= true;
}

else{
    flag=false;

}

return flag;


}
Run Code Online (Sandbox Code Playgroud)

Xcode警告我,在以下行:

 if (B[row][col] != a[row][col])
Run Code Online (Sandbox Code Playgroud)

type'const Matrix'不提供下标运算符

注意:此代码部分中省略了函数头,构造函数和其他函数.

任何帮助将不胜感激.谢谢.

Lio*_*gan 5

鉴于您的实施,它应该是 if (B.a[row][col] != a[row][col])

顺便说一句:如果你计划实现自己的矩阵类,你应该阅读这个页面.