#include <iostream>
//实现 << 运算符重载
class Person
{
public:
int age;
int salary;
};
std::ostream& operator<<(std::ostream &o1,Person p1)
{
o1 << p1.age << " " << p1.salary;
return o1;
}
int main()
{
Person p1;
p1.age = 101;
p1.salary = 2000;
std::cout << p1<<std::endl;
return 0;
}
<<运算符重载(3)
最新推荐文章于 2024-08-16 23:08:36 发布