classNumber{public:Number&operator++();// prefix ++: no parameter, returns a referenceNumberoperator++(int);// postfix ++: dummy parameter, returns a value};
Object non-member function:
This is another way to do this: As long as the functions are in the same namespace as the object they are referring too, they will be considered when the compiler will search for a fonction to handle ++t ;or t++ ; code:
class T
{// etc.};
T &operator++(T & p_oRight)// ++A{// Do increment of p_oRight valuereturn p_oRight ;}
T operator++(T & p_oRight,int)// A++{
T oCopy ;// Copy p_oRight into oCopy// Do increment of p_oRight valuereturn oCopy ;}
The difference lies in what signature you choose for your overload(s) of operator ++.
classNumber{public:Number&operator++();// prefix ++: no parameter, returns a referenceNumberoperator++(int);// postfix ++: dummy parameter, returns a value};