I just don't see my mistake. There are so many questions regarding this error message and either the answers don't apply or I just can't see that they apply. Maybe the error message should be improved?
Matrix a = Matrix(3, 4);
// fill a with values
Matrix c = Matrix(4, 4);
// fill c with values
a *= c - c; //this is where the compile error occurs
When I change the line to a *= c
it works. So I guess there is nothing wrong with the *= operator.
This is the Matrix *= operator:
Matrix &Matrix::operator *=(Matrix &B)
{
Matrix M(rows(), B.cols());
for (int i = 0; i<rows(); i++)
{
for (int j=0; j<B.cols(); j++)
{
for (int k=0; k<cols(); k++)
{
M(i,j) = M(i,j) + (*this)(i,k) * B(k,j);
}
}
}
return M;
}
And this is the -operator:
Matrix operator -(Matrix &A, Matrix &B)
{
//TODO: Check if matrices have same dimensions, exception else
Matrix M(A.rows(), A.cols());
for(int i=0; i<A.rows(); i++)
{
for(int j=0; j<A.cols(); j++)
{
M(i,j) = A(i,j)-B(i,j);
}
}
return M;
}