#include <iostream>
#include <string>
#include <vector>
using namespace std;
//建筑物类
class Building {
//goodGay全局函数是 Building好朋友, 可以访问Builfing中私有成员
friend void goodGay(Building* building);
public:
Building() {
m_SittingRoom = "客厅";
m_Bedroom = "卧室";
}
string m_SittingRoom;//客厅
private:
string m_Bedroom;//卧室
};
//全局函数
void goodGay(Building *building) {
cout << "好基友全局函数 正在访问:" << building->m_SittingRoom<<endl;
cout << "好基友全局函数 正在访问:" << building->m_Bedroom<< endl;
}
void test01() {
Building building;
goodGay(&building);
}
int main() {
test01();
return 0;
}
《c++》全局函数做友元
最新推荐文章于 2024-08-24 14:01:36 发布