yamokosk
July 9th, 2004, 09:07 AM
Alright, i have starred at this for sometime, and while i could try every combination of const modifier, I would rather get an explanation why this won't go. I still get hung up on const stuff...
Matrix& Matrix::operator = (const Matrix& m) {
if (*this == m) {
for (int r = 0; r < rows(); r++) {
for (int c = 0; c < cols(); c++) {
(*this)(r,c) = m(r,c);
}
}
return *this;
} else {
throw std::invalid_argument("Error! Matricies must be equal for assignment.");
}
}
I get the following error on compile:
error C2662: 'cols' : cannot convert 'this' pointer from 'const class Matrix' to 'class Matrix &'
Conversion loses qualifiers
error C2662: 'rows' : cannot convert 'this' pointer from 'const class Matrix' to 'class Matrix &'
Conversion loses qualifiers
Thanks in advance!
Matrix& Matrix::operator = (const Matrix& m) {
if (*this == m) {
for (int r = 0; r < rows(); r++) {
for (int c = 0; c < cols(); c++) {
(*this)(r,c) = m(r,c);
}
}
return *this;
} else {
throw std::invalid_argument("Error! Matricies must be equal for assignment.");
}
}
I get the following error on compile:
error C2662: 'cols' : cannot convert 'this' pointer from 'const class Matrix' to 'class Matrix &'
Conversion loses qualifiers
error C2662: 'rows' : cannot convert 'this' pointer from 'const class Matrix' to 'class Matrix &'
Conversion loses qualifiers
Thanks in advance!