我正在努力让我的头绕着运算符重载。在这种情况下,我有+运营商和我试过的例子,任何帮助将不胜感激。运算符重载C++的建议
我得到它说“invaild使用‘类矩阵’我不确定如何解决这个问题我怎么能添加这两个矩阵的对象一起错误?
Matrix Matrix::operator+(const Matrix& rhs){
return Matrix(Matrix + rhs.Matrix());
}
Matrix::Matrix(int MM, int NN){
M = MM;
N = NN;
data = new double[M * N];
for (int i =0; i < M; i++)
{
for (int j = 0; j < N; j++)
{
data[i* N+j] = (double) 1000 + i*N+j;
// cout << data[i*N+j] <<"\t";
}
//cout <<"\n";
}
cout << "Matrix Constructor... (code to be implemented here!!!)\n";}
感谢
你的问题是什么? – Christian 2012-04-06 10:52:05
关于运算符重载的一个很好的阅读http://courses.cms.caltech.edu/cs11/material/cpp/donnie/cpp-ops.html – Marius 2012-04-06 12:31:23