我正在努力讓我的頭繞着運算符重載。在這種情況下,我有+運營商和我試過的例子,任何幫助將不勝感激。運算符重載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