Results 1 to 14 of 14

Thread: overloading ++ --

Threaded 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 overloading ++ --

    Hi, I overloading ++ and -- (postfix and prefix way) for my class Person with attributes _age, _name and _sex; but I have some problems and warning; ++ on Person must to increment the _age; both them incremet properly the objects Person.....
    Qt Code:
    1. const Person& operator++() { //prefix //this seems me OK
    2. _age++;
    3. return *this;
    4. }
    5.  
    6. const Person& operator++(int) { //postfix
    7. Person before;
    8. _age++;
    9. return before;
    10. }
    11. warning person.h:37: warning: reference to local variable `before' returned
    To copy to clipboard, switch view to plain text mode 

    Is the second good (at the moment I'd like avoid "friend" member) ? Is a way to keep out that boring "warning", please?
    Last edited by mickey; 3rd January 2008 at 21:39.
    Regards

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.