class Person
{
public:
Person(string name, int age)
{
this->m_name = name;
this->m_age = age;
}
string m_name;
int m_age;
};
ostream &operator<<(ostream &cout ,const Person &p)
{
cout << "m_name=" << p.m_name << endl;
cout << "m_age=" << p.m_age << endl;
return cout;
}
void test01()
{
Person p1("张三", 20);
cout << p1 << endl;
}
int main()
{
test01();
return 0;
}
左移运算符重载
最新推荐文章于 2024-08-30 16:00:44 发布