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:
Code:
const Matrix Matrix::operator=(const Matrix &temp)
{
if(this == &temp)
return *this; // to prevent bad things from happening..
int x;
int y;
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];
}
}
return *this;
}
I get the following error:
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:
http://dydx.no-ip.com:8080/matrix.cpp
http://dydx.no-ip.com:8080/matrix.h
Thanks all!