|
-
April 8th, 2010, 09:50 AM
#2
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|