我有一個類,存儲動態二維數組的對象'矩陣'。我試圖超載'='運算符,以便1個矩陣可以複製到另一個矩陣。重載運算符和鏈接
以下工作:
Square_Matrix a,b,c;
a = b;
然而,這不起作用:
a = b = c;
^它給了我下面的錯誤1)敵不過運營商=(操作數類型是「方陣'和'void')..... 2)從'void'到'const Square_Matrix'的參數1沒有已知的轉換
我該如何解決這個問題?
//header file
void operator=(const Square_Matrix& Par2);
//.cpp file
void Square_Matrix::operator=(const Square_Matrix& Par2){
if (size != Par2.size){
cout << "Matrices are of different size" << endl;
} else {
for (int i = 0; i < N; i++){
for (int j = 0; j < N; j++){
matrix[i][j] = Par2.matrix[i][j];
}
}
}
}
編輯:nvm,完美無瑕。非常感謝,這可能是一個愚蠢的簡單問題 – Foxic