Click to See Complete Forum and Search --> : C++ Operator: How to overload postfix increment and decrement operators?


Yves M
February 13th, 2003, 01:17 PM
Q: How do I overload the postfix increment and decrement operators? (as in x++ or x--)?

A: To specify the postfix increment and decrement operators, you must specify an int as an argument:


class MyClass
{
public:
MyClass& operator++(); //Prefix increment operator (++x)
MyClass operator++(int); //Postfix increment operator (x++)

MyClass& operator--(); //Prefix decrement operator (--x)
MyClass operator--(int); //Postfix decrement operator (x--)
};


FAQ contributed by: [Kevin Hall (http://www.codeguru.com/forum/member.php?u=85152)]
<br><br>