题解 | 友元全局函数
#include <iostream> using namespace std; class Person { // write your code here...... friend void showAge(Person& P); public: Person(int age) { this->age = age; } private: int age; }; void showAge(Person& p) { cout << p.age << endl; } int main() { Person p(10); showAge(p); return 0; }