#include <iostream>
using namespace std;
#include <string>
//全局函数做友元
//建筑物类
class Building
{
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()
{
system("color f5");
test01();
system("pause");
return 0;
}
C++中全局函数做友元
最新推荐文章于 2024-11-04 19:24:37 发布