【发布时间】:2011-12-11 07:07:18
【问题描述】:
大家:
我正在创建一个程序,该程序能够为学校的课程创建矩阵并对其执行各种操作。它们要求我们使用适当的矩阵运算重载运算符。
我很难使用以下功能:
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;
}
Xcode 在以下行警告我:
if (B[row][col] != a[row][col])
type 'const Matrix' 不提供下标运算符
注意:此代码部分省略了函数头、构造函数和其他函数。
任何帮助将不胜感激。 谢谢。
【问题讨论】:
标签: c++ pointers matrix operator-overloading