(e-mail address removed) (Michiel Salters) wrote
In fact, efficiency doesn't matter. No argument is actually passed
to the function, just as the =0 in a pure virtual funcion is not
actually an assignment.
int was probably chosen because the postfix ++ adds 1, and 1 is
an int.
Sorry, that's not correct.
13.5.7 Increment and decrement
The user-defined function called operator++ implements the prefix
and postfix ++ operator. ...
If the function is a member function with one parameter (which
shall be of type int) or a non-member function with two parameters
(the second of which shall be of type int), it defines the postfix
increment operator ++ for objects of that type. When the postfix
increment is called as a result of using the ++ operator, the int
argument will have value zero.
There follows an example in which they call a.operator++(0) and
operator++(b,0) explicitly passing the value of the int.
// MY example, shorter than the one in the standard
#include <iostream>
using namespace std;
struct Foo {};
Foo &operator++(Foo &lhs, int rhs)
{ cout << "rhs is " << rhs << endl; return lhs; }
int main() {
Foo f;
f++; // rhs is 0
operator++(f,27); // rhs is 27
}
Using the second parameter in operator++ is unusual at best, and
obfuscated at worst -- but it's legal.