全局函数做友元
#include <iostream>
using namespace std;
#include <string.h>
class Building
{
friend void goodGay(Building* building);
public:
Building()
{
SittingRoom = "客厅";
BedRoom = "卧室";
}
private:
string BedRoom;
public:
string SittingRoom;
};
void goodGay(Building* building)
{
cout << "正在访问: " << building->SittingRoom << endl;
cout << "正在访问: " << building->BedRoom << endl;
}
void test01()
{
Building b1;
goodGay(&b1);
}
int main()
{
test01();
system("pause");
return 0;
}
类做友元
class Building
{
friend class goodGay;
}
成员函数做友元
class Building
{
friend void GoodGay::visit();
}