I have a problem. I have implemented a custom operator*
as a member function.
In header:
class Matrix
{
public:
Matrix operator*(int arg); //(1)
...
}
Matrix operator*(int a, const Matrix& m)
{
return m * a; //(2)
}
(1) I can do this in main.cpp:
Matrix a = Matrix::GetRandom.....
Matrix b = a * 2;
(2) On this line, I'm getting a compiler error:
IntelliSense: no operator "*" matches these operandsnoperand types are: const Matrix * int
How do I fix it?
friend Matrix operator(Matrix, int);
andfriend Matrix operator(int, Matrix);
. This keeps both symmetrical and they're declared next to each other. – dyp