- 友元
- 全局函数作为友元函数
- 利用friend关键字让全局函数 goodGay作为本类好朋友,可以访问私有成员
- friend void goodGay(Building * buliding);
- 类作为友元类
- 让goodGay类作为 Building的好朋友,可以访问私有成员
- friend class GoodGay;
- 类中的成员函数作为友元函数
- //让GoodGay类中的 visit成员函数作为友元
- friend void GoodGay::visit();
例如卧室是私有的,通常只能自己访问,但对于闺蜜,可能可以单独让他访问,这个闺蜜就是类似友元。
全局函数作为友元函数
类作为友元类
类中的成员函数作为友元函数