成员函数做友元
#include <iostream>
using namespace std;
class Building;
class Goodgey
{
public:
Goodgey();
void visit01();
void visit02();
Building *building;//定义指针变量
};
class Building
{
public:
Building();
friend void Goodgey::visit02();
public:
string m_sittingroom;
private:
string m_Bedroom;
};
//类外定义构造函数
Building::Building()
{
m_sittingroom="客厅";
m_Bedroom="卧室";
}
//类外定义成员函数
void Goodgey::visit01()
{
cout<<building->m_sittingroom<<endl;
}
void Goodgey::visit02()
{
cout<<building->m_sittingroom<<endl;
cout<<building->m_Bedroom<<endl;
}
Goodgey::Goodgey()
{
building=new Building;//
}
int main()
{
Goodgey gg;
gg.visit01();
gg.visit02();
return 0;
}