Implementing Operator Functions
The general format of the Operator function is:
return_type operator op ( argument list );
Where op is the symbol for the operator being overloaded. Op has to be a valid C++ operator, a new symbol cannot be used.
e.g.
Let us consider an example where we overload unary arithmetic operator '++'.
class Counter
{
public :
Counter();
void operator++(void);
private :
int Count;
};
Counter::Counter()
{
Count = 0;
}
void Counter::operator++(void)
{
++ Count ;
}
void main()
{
Counter c1;
c1++; // increments Count to 1
++c1; // increments Count to 2
}