#include <iostream>
#include "string"
using namespace std;
class Building;
//类做友元
class GoodGay {
public:
Building *building;
//成员函数做友元
void visit();
GoodGay();
};
class Building {
public:
// friend void goodGay(Building &building);
// friend class GoodGay;
friend void GoodGay::visit();
string m_SittingRoom;
Building() {
m_SittingRoom = "客厅";
m_BedRoom = "111";
}
private:
string m_BedRoom;
};
//全局函数做友元
//void goodGay(Building &building) {
// cout << "============" << building.m_BedRoom << endl;
//}
GoodGay::GoodGay() {
building = new Building;
}
void GoodGay::visit() {
cout << building->m_BedRoom << endl;
}
int main() {
// Building building;
// goodGay(building);
return 0;
}
C++友元
最新推荐文章于 2024-11-09 20:38:27 发布