postfix increment doubt !!

Started by
1 comment, last by Zahlman 13 years, 9 months ago
when we overload postfix operator ,
by using this ::

<class name> operator++ (int) ..
how does this int tells the compiler that we are overloading postfix and not prefix operator ??

Thanks in advance
y2jsave
Advertisement
The unused "int" argument is the disambiguator. In no way intuitive or obvious, but that is C++.
<class name> operator++ (int) is always the postfix ++, because of the (int) parameter. That parameter is ignored (because incrementing always increments by 1).

<class name> operator++ () is always the prefix ++, because it does not have the (int) parameter.

This topic is closed to new replies.

Advertisement