#include<iostream>
using namespace std;
#include<string>
class building{
friend void goodgay::visit1();//goodgay类下的visit成员函数作为奔雷的好朋友,可以访问私有成员
public:
building();//构造函数
string m_sittingroom;
private:
string m_bedroom;
};
class goodgay{
public:
goodgay();
void visit1();//让visit可以访问building中的私有成员
void visit2();
//让visit不可以访问building中的私有成员
building * b;
};
//类外实现成员函数
building::building(){
m_sittingroom="客厅";
m_bedroom="卧室";
}
goodgay::goodgay(){
b = new building;
}
void goodgay::visit1(){
cout<<"visit1正在访问 :"<<building->m_bedroom<<endl;
}
void goodgay::visit2(){
cout<<"visit2正在访问 :"<<building->m_sittingroom<<endl;
}
void test01(){
goodgay gg;
gg.visit1();
}
int main(){
test01();
return 0;
}