C++ Operator: How to overload postfix increment and decrement operators?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

Thread: C++ Operator: How to overload postfix increment and decrement operators?

Hybrid View

  1. #1
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588

    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]


    Last edited by Andreas Masur; July 24th, 2005 at 04:34 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center