I have created a class Matrix which basically represents a mathematical matrix. In order to use a scalar-matrix multiplication, I have overloaded the * operator as:
Matrix Matrix::operator*(double scalar) const
{
Matrix result(*this);
result *= scalar;
return result;
}
To make the operator work from left as well, I have used:
Matrix operator*(double a, const Matrix &M)
{
return M * a;
}
Given Matrix M and double s, M * s works fine but s * M gives me an error:
Error C2677: binary
*: no global operator found which takes typeMatrix(or there is no acceptable conversion)
while the IDE shows me the error: "no operator * matches these operands".
Any idea what could be the problem?
Edit: That was a stupid mistake! I hadn't declared the operator in the header and the compiler couldn't see the declaration! So sorry for that...