Results 1 to 14 of 14

Thread: overloading ++ --

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Qt products
    Qt3
    Platforms
    Windows
    Thanks
    53

    Default Re: overloading ++ --

    hello,
    refering to my post #10, could you show me any examples of operations (assigment or other) for which at first the returned value of operator+= has to be 'const' and at second, examples for which returned value of operator+= mustn't be 'const' ?
    (my problem is 'const' on returned value....)
    Thanks.
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: overloading ++ --

    Quote Originally Posted by mickey View Post
    could you show me any examples of operations (assigment or other) for which at first the returned value of operator+= has to be 'const' and at second, examples for which returned value of operator+= mustn't be 'const' ?
    There are no "must" or "musn't" in this case, but you don't gain anything if you return const reference instead of plain reference.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: overloading ++ --

    I can't think of any situation where the return value of operator+= would have to return a const object. You can do that of course but I just don't see a point.

    Qt Code:
    1. X x;
    2. x+=7; // OK
    3. x = ++(x+=7); // invalid for const & operator+=
    To copy to clipboard, switch view to plain text mode 
    The last line would be invalid if operator+= returned a const object.

Similar Threads

  1. Simple: Operator overloading with heap objects
    By durbrak in forum General Programming
    Replies: 12
    Last Post: 25th April 2007, 13:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.