The local variable
temp
goes out of scope when the function returns and is no longer valid afterwards.
So you should return a value here rather a reference:
Human Human::operator++(int){
Human temp(*this);
operator++();
return temp;
}
[EDIT]
See also here
http://en.cppreference.com/w/cpp/language/operator_incdec[
^] the
Notes below the table:
Quote:
Prefix versions of the built-in operators return references and postfix versions return values
I suggest also to bookmark the above website en.cppreference.com (or a similar one) in your browser. It will be really helpful while trying out C++ features.