Re: postfix and prefix operator overloading question
Originally Posted by LarryChen
My question is that why prefix returns by value and postfix returns by reference?
You actually mean to ask why the prefix version returns by reference and the postfix version returns by value. We normally expect the prefix version to return the updated value, hence it would typically return *this; Therefore, there is no point in returning by value when you do not need a copy. But we normally expect the postfix version to return the previous value, hence it is sensible to return a copy of the object before the increment.
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar
Bookmarks