请教: 操作符+重载 和 const member function
请高手帮忙解释一下,rhs类型是const X&, b+c返回怎么成 const X了?
class X{
public:
X& operator= (const X& rhs){ return *this;};
const X& operator+ (const X& rhs) const{ return rhs;} ; //rhs类型是const X&, b+c返回怎么成 const X了?
const X& operator+ (int m){ return *this;};
private :
int n;
};
int main()
{
X a,b,c;
//以下哪行编译有问题?
(c=a+a) = b+ c ;
//a=b+c+5; //编译为何出错? Error: The operation "const X + int" is illegal.
a=a+5+c;
a=b+5;
a=a=b+c;
}