C++ Operator: How to overload postfix increment and decrement operators?
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:
Code:
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]
<br><br>