If you want to concatenate assignment like this int x, y, z; x = y = z = 15; The convention is to make the assignment operators return a reference to *this. 11 Handle assignmnet to self in operator = You can easily assign an object to itself without…
关于赋值,可以写成连锁形式: int x, y, z; x = y = z = 15; //赋值连锁形式 赋值采用右结合律,故上述赋值被解析为: x = (y = (z = 15)); 为了实现连锁赋值,赋值操作符必须返回一个reference引用指向操作符的左侧实参. 下面示例是为classes实现赋值操作符时应该遵循的协议: class Widget { public: ... Widget& operator=(const Widget& rhs) //返回类型是个reference…