passing discards qualifiers? overloading =...
I'm _attempting_ to overload the assignment operator so I can safely set one object equal to another.
Here's my code for the operator overloading:
I get the following error:
const Matrix Matrix::operator=(const Matrix &temp)
if(this == &temp)
return *this; // to prevent bad things from happening..
int r = temp.numR();
int c = temp.numC();
for(x = 0; x < r; x++)
for(y = 0; y < c; y++)
Array[x][y] = temp.Array[x][y];
matrix.cpp: In member function `const Matrix Matrix::operator=(const Matrix&)':
matrix.cpp:307: passing `const Matrix' as `this' argument of `int Matrix::numR()' discards qualifiers
matrix.cpp:308: passing `const Matrix' as `this' argument of `int Matrix::numC()' discards qualifiers
All of the examples of overloading = say that the declaration should be like so:
const Matrix &Matrix::operator=(const Matrix &temp)
but that further complicates my program, since I don't declare my objects on the heap. What to do about that if it really matters?
And here is the rest of the code for reference: