1. 程式人生 > >讀書筆記《Effective c++》 條款10 令operator= 返回一個reference to *this

讀書筆記《Effective c++》 條款10 令operator= 返回一個reference to *this

這個主要的點是,賦值可以寫成連鎖形式:

int x, y, z;

x = y = z =15;

class Widget
{
public:
	Widget& operator+=(const Widget& rhs)
	{
		//...
		return *this;
	}
	Widget& operator=(int rhs)
	{
		//...
		return *this;
	}
	//...
};