class Person
{
friend std::ostream &operator<<(std::ostream &out, Person &person);
public:
void name_set(const std::string &name)
{
m_name = name;
}
void age_set(int age)
{
m_age = age;
}
private:
std::string m_name;
int m_age;
};
std::ostream &operator<<(std::ostream &out, Person &person)
{
out << "name: " << person.m_name << ", age: " << person.m_age;
}
int main()
{
Person p;
p.name_set("furong");
p.age_set(10);
std::cout << p << std::endl;
return 0;
}
$ ./a.out
name: furong, age: 10