The return type must make sense to your need.
The difference among returning value, reference, and constant reference are:
1. Returning value needs copy constructor, it could be slow but you own the value.
2. Returning reference needs to make sure you don't return reference to a local variable but it is efficient and you can change the value it references to.
3. Returning constant reference is the same as returning reference except you can not change the value it references to.
Example:
Assume you have class A with assiment operator and following application:
A a,b,c;
...
a = b;
...
a = b = c;
...
No matter what the assignment operator returns, A, A&, or const A&, "a = b;" works fine with difference in performance.
If the return type is A or const A&, a=b=c cause error because it meants ((a=b)=c). Since a=b returns A or const A&, both are rvalue (can only be placed at right hande side of an assignment), they can not be used as lvalue (can be placed at left hande side of an assignment).
If the return type is A&, a=b=c is legal because A& is lvalue.
返回引用可以使对象成为左值,而传值不行.do_do说的很清楚了
A a,b,c;
//operator= code
a = b;//用A或const A&工作的很好
a = b = c;//这时就不行了,这时要求a = b的结果是左值,即(a = b) = c;这里要用A&,而const A&返回的是常量,所以也不行