Why does the postfix increment operator take a dummy parameter?

Viewed 11347

Have a look at these function signatures:

 class Number {
 public:
   Number& operator++ ();    // prefix ++
   Number  operator++ (int); // postfix ++
 }; 

Prefix doesn't take any parameter but postfix does. Why? I thought we can recognize them with different return types.

6 Answers

The compiler uses the int argument to distinguish between the prefix and postfix increment operators. For implicit calls, the default value is zero so actully it does not make so much difference in functionality of overloaded operator...

Related