C++ Overloading Operators Postfix Prefix


   C++ overloading clearly advocates simplicity in usage and readability. That is why all forms of operators are getting overloaded to give natural and domain oriented meanings.
The increment operator ++ can be called in two forms post fix and pre fix. The programmers will have a slight difficulty in overloading/using it because, they won’t know how to differentiate them. That is why postfix operators are created with a dummy parameter of type int.
The prefix ++ operator can be overloaded as such, without any change. Look at the function/operator definition.


class Test
{
int i;
public:
void operator ++()
{
++i;
}
};

The post fix ++ operator will be overloaded with a dummy integer parameter as follows.

Class Test
{
int i;
public:
void operator ++(int)
{
i++;
}
};

Similar method of overloading is used for the — post/prefix operators also.
The stream operators << and << need a different type of treatment. Though these kind of techniques make the life of the developer difficult, it is the user who is going to be benefited the most.