Why Operator Overloading & return values?

In fact, we overloaded operator returns void, returns the object itself, returns the object reference are possible, does not mean that we must return to a reference, but need a different return values ​​under different circumstances

 

So under what circumstances we want to return an object reference to it?
There are two reasons:
① allow continuous assignment
② prevent the return of the object (returned object can also be continuous assignment) is called when the copy constructor and destructor cause unnecessary overhead, reducing the efficiency of the assignment operator and the like.

For the second reason: if the mode "transfer value", although still function correctly, but return * this statement should be copied to save the return value in an external storage unit, an increase of unnecessary overhead, reduce assignment efficiency function.



Author: wuxinliulei
link: https: //www.zhihu.com/question/22821783/answer/65033250
Source: know almost
 

Guess you like

Origin blog.csdn.net/qq_26079093/article/details/92991710