条款 10:令 operator= 返回一个 reference to *this
Have assignment operators return a reference to *this.
为了下列实现“连锁赋值”,需要令赋值操作符返回一个操作符左侧实参的引用
a = b = c = 15;
Widget& operator=(const Widget& ths)
{
...
return *this;
}
Widget& operator=(int rhs)
{
...
return *this;
}
这并非强制性,但所有内置类型和标准程序库提供的类型如:string、vector、complex、shared_ptr 都遵守。