#include<iostream>
#include<string>
using namespace std;
//建筑物类
class Building
{//全局函数作为Building类的友元 可以访问Buildign的私有成员
friend void goodGay(Building *building);
public:
Building() {
m_SittingRoom = "客厅";
m_BedRoom = "卧室";
}
public:
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();
system("pause");
}
4.4.1全局函数做友元
最新推荐文章于 2024-11-06 21:00:46 发布