Possible Duplicate:
How to overload unary minus operator in C++?
I have a class C that overloads a number of operators:
class C
{
...
C& operator-=(const C& other) {...}
const C operator-(const C& other) {...}
}
inline const C operator*(const double& lhs, const C& rhs)
Now I wanted to invert an object of type C
c = -c;
And gcc gives me the following error:
no match for >>operator-<< in >>-d<<
candidate is: const C C::operator-(const C&)
Using c = -1*c works, but I'd like to be able to shorten that. What's missing in my class?
Solved: added the unary operator-:
C operator-() const {...}
as a member of C.