c++ - Operator overloading: No match for 'operator[]' -
The object in this square is 'mPoint' which stores a dynamic 2D array. I am trying to make it so that these two matrixs can be compared whether they are equivalent or no. So I'm overloading operator '=='.
I am getting an error "There is no match for operator []" (Operand type 'square_matrix and' int ') "If (MP [I]] [J]! = Para [ I] [j]) ".cpp file. How can I fix it? I am very new in the operating code
// header file #include namespace Using std; square square matrix {public: int ** mpoint; integer size; zero set_ize (int newis); bulg operator == (square yu Tricks para);
.
// CPP file #include & lt; iostream & gt; namespace std; #include "Square_Matrix.h" void For square_Matrix :: Set_Size (int new_size) {for (int i = 0; i
You have your problem in this line if (mPoint [i] [Ja]! = Paras [ii] [ja]) << code> You are trying to apply operator [] []
directly to the example of Square_Matrix
. Why is it that the compiler says that for operators [] '' '
"there is no match" you should use something like if (mPoint [i] [j]! = Par .mPoint [i] [j]) {<>> To fix this I think this is a typo. It is better to pass const squirabricks and
as the parameter to your operator ==
in your header file, Bool operator == (const squar_attics & para);
and in the CPP file
bool Square_Matrix :: operator == (Const square gatrix and para) {// your argument}
Comments
Post a Comment