#include<iostream>
#include<string>
using namespace std;
class Building;
class goodGay {
public:
goodGay();
void visit();
Building *building;
};
class Building {
friend class goodGay;
public:
Building();
public:
string m_SittingRoom;
private:
string m_BedRoom;
};
Building::Building()
{
this->m_SittingRoom = "客厅";
this->m_BedRoom = "卧室";
}
void goodGay::visit()
{
cout << "好基友正在访问" << building->m_SittingRoom << endl;
cout << "好基友正在访问" << building->m_BedRoom << endl;
}
goodGay::goodGay()
{
building = new Building;
}
void test01() {
//Building b;
goodGay gg;
gg.visit();
}
int main() {
test01();
system("pause");
return 0;
}
实验下来,类的函数的实现必须在类外实现才不报错。我把visit()直接在类里面实现就编译报错了。这个可能更c++编译机制有关,以后有时间好好研究下。先这么用着