int x, y, z;
x = y = z = 15;
在c++中=
是右结合(right-associative),所以可以按以上方式进行链式的使用。
为了支持以上方式,我们自己所写的数据类型需要按以下方式进行实现
class Widget{
public:
Widget& opoerator=(const Widget& rhs) {
...
return *this;
}
Widget& opoerator+=(const Widget& rhs) {
...
return *this;
}
};