#include<iostream>
using namespace std;
class CGirl {
friend ostream& operator<<(ostream& cout, const CGirl& g);
string m_name;
int m_xw;
int m_score;
public:
CGirl() { m_name = "zhongge"; m_xw = 87; m_score = 30; }
void show() {
cout << "name:" << this->m_name << ", xw:" << this->m_xw << ", score:" << this->m_score << endl;
}
};
ostream& operator<<(ostream& cout, const CGirl& g) {
cout << "name:" << g.m_name << ", xw:" << g.m_xw << ", score:" << g.m_score << endl;
return cout;
}
int main() {
CGirl g;
cout << g << endl;
return 0;
}
左移运算符的重载只能用全局函数的方式,不能用成员函数。
cout是ostream类的对象