When I try to compile the following (g++ 4.6.3)
class A {};
A& operator*=( A& a, const A& b )
{
return a;
}
A operator*( const A& a, cons
Like Lucian said, you cannot bind a temporary object to a non-const reference. The expectance of the compiler is that the object will cease to exist after the expression so it makes no sense to modify it.
To fix your code, remove the temporary (making the argument const&
makes no sense in operator *=
):
A operator*(A a, const A& b)
{
return a *= b;
}