我试图在 C++ 上学习一些运算符重载方法,然后我遇到了这个错误:
错误 7 错误 C2228: '.values' 的左侧必须有类/结构/联合
还有另一个错误说:
错误 4 错误 C2065:“总和”:未声明的标识符
Matrix<type> Matrix<type>::operator+(const Matrix& m){
if(num_of_rows != m.num_of_rows || num_of_cols != m.num_of_cols) // Checking if they don't have the same size.
Matrix<type> *sum;
sum = new Matrix<type>(num_of_rows, num_of_cols);
for(int i = 0; i < num_of_rows; i++)
for(int j = 0; j < num_of_cols; j++)
sum.values[i][j] = values[i][j] + m.values[i][j];
return *sum;
}
有人能告诉我哪里做错了吗?