The object of the class 'Square_Matrix' stores an integer matrix.
Is this how I can check if two matrices are equivalent? I want to compare two 2d arrays by overloading '==' to check if every element is identical between the 2 matrices.
E.g: I need the following to work:
Square_Matrix a,b;
if (a == b) {return 1;}
Both a and b are dynamic 2d arrays.
However, I'm getting an error: unexpected initializer before 'operator'. How can I fix this? Other than that, is this how the syntax should look like?
//header file
bool operator==(Square_Matrix array1, Square_Matrix array2);
//.cpp file
bool Square_Matrix operator ==(Square_Matrix array1, Square_Matrix array2){
if (array1.size != array2.size){
return false;
}
for (int i = 0; i < array1.size; i++){
for (int j = 0; j < array1.size; j++){
if (array1[i][j] != array2[i][j]){
return false;
}
}
}
return true;
}