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.....
const Person& operator++() { //prefix //this seems me OK
_age++;
return *this;
}
const Person& operator++(int) { //postfix
Person before;
_age++;
return before;
}
warning person.h:37: warning: reference to local variable `before' returned
const Person& operator++() { //prefix //this seems me OK
_age++;
return *this;
}
const Person& operator++(int) { //postfix
Person before;
_age++;
return before;
}
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?
Bookmarks