Categories
不学无术

为什么operator

http://www.cnblogs.com/this-543273659/archive/2011/09/01/2161574.html
如果是重载双目操作符(即为类的成员函数),就只要设置一个参数作为右侧运算量,而左侧运算量就是对象本身。。。。。。
而 >>  或<< 左侧运算量是 cin或cout 而不是对象本身,所以不满足后面一点。。。。。。。。就只能申明为友元函数了。。。
如果一定要声明为成员函数,只能成为如下的形式:
ostream & operator<<(ostream &output)
{
return output;
}
所以在运用这个<<运算符时就变为这种形式了:data<<cout;
不合符人的习惯。

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.