标签:
ostream & ostream::operator<<(int n){ ……//输出n的代码 return *this; // *this 就是cout }
class Complex { public: int a,b; }; ostream &operator<<(ostream &os, Complex &x){ //cout<<x<<endl; os<<x.a<<"+i"<<x.b; // the "os<<x.a" is os.operator<<(x.a); // and in the definition of os.operator<<(), it should returned *this // which represents a ostream object return os; }
标签:
原文地址:http://www.cnblogs.com/XingyingLiu/p/5154871.html