c++可以通过对自定义类的运算符重载使得自定义类可以像int string等一样方便地进行+ - × / 和输入输出等操作,类的运算符重载方式可以通过定义成员函数或者通过友元函数的方式重载,其中运算符<<和>>只能通过友元函数的方式重载,http://en.cppreference.com/w/cpp/language/operators 这里解释道:
Since they take the user-defined type as the right argument (
b
in
a@b
), they must be implemented as non-members. 另外可以看msdn: https://msdn.microsoft.com/en-us/library/1z2f6c2k.aspx