Reputation: 25898
Why in C++ the prefix return a reference but the postfix return a value?
Upvotes: 1
Views: 1891
Reputation: 84189
Because with prefix you modify the object and then return it (so it can be lvalue), and with postfix you return the unchanged object (i.e. a copy) and only then update it (this is of course done by first storing the copy in a temporary, updating the original object, and then returning the temporary by value.)
Upvotes: 4