- #71
yungman
- 5,755
- 293
I am reviewing math operators overloading. I have a question about math overloading operator xx (). Say I want to have a return of class object what is the difference between:
I actually tried both, seems like both return object result even though line 3 claims return type is a reference. I don't understand this. Can anyone elaborate this a little?
Thanks
C++:
class Test;
Type A,B;
// operator xx where xx can be +, -, *, / etc.
Test& operator xx ( const Test &rhs){Test result; ... ; return result;}//declare return type as reference.
Test operator xx ( const Test &rhs){Test result; ... ; return result;}//declare return type is Test Object.
I actually tried both, seems like both return object result even though line 3 claims return type is a reference. I don't understand this. Can anyone elaborate this a little?
Thanks