pre & post increment & decrement operators

This tip submitted by jay on 2005-05-05 14:05:47. It has been viewed 41247 times.
Rating of 5.4 with 233 votes




consider the operator ++ for the INT class just discussed.the reqirement is to have the operators ,
++a
&
a++

++a will be resolved as a.operator ++()
a++ will be resolved as a. operator ++(0)

In order to avoid this confusion , all postfix unary operators take in a dummy integer .

Thus,
++a will be resolved as a.operator ++()
a++ will be resolved as a. operator ++(0)






More tips

Help your fellow programmers! Add a tip!