#include<iostream>
using namespace std;
class Person
{
friend void test01();
friend ostream& operator<<(ostream& cout, Person& p);
private:
int m_A;
int m_B;
};
ostream& operator<<(ostream &cout, Person &p)//只能使用全局函数重载<<
{
cout << p.m_A << endl;
cout << p.m_B << endl;
return cout;
}
void test01()
{
Person p;
p.m_A = 10;
p.m_B = 10;
cout << p;
}
int main()
{
test01();
}
重载运算符<<
![](https://img-home.csdnimg.cn/images/20240711042549.png)