I am not using this code in any production environment, it is just for my understanding. Is this code valid (i.e. can I define my postfix operator like this?):
class A
{
public:
A& operator++(int n)
{
std::cout<<"N is:"<<n<<"\n";
return *this;
}
};
int main()
{
A a;
a++;
a.operator ++(10);
}
On VS2008, I get the output as:
N is 0
for first call and
N is 10
for second call
This behavior is legal and well defined in 13.5.7: