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
postfix increment doubt !!
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.
<class name> operator++ () is always the prefix ++, because it does not have the (int) parameter.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement