1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| #include<iostrean> #include<string> using namespace std; class GoodGay{ public: GoodGay(); void visit(); void visit2(); private: Building *building; } class Building{ friend void GoodGay::visit(); public: Building(); public: string m_livingroom; private: string m_bedroom; }
Building::Building(){ m_livingroom = "客厅"; m_bedroom = "卧室"; } GoodGay::GoodGay(){ building = new Building(); } GoodGay::void visit(){ cout <<building->m_livingroom <<endl; cout <<building->m_bedroom <<endl; } GoodGay::void visit2(){ cout <<building->m_livingroom <<endl; } int main(){ GoodGay gg; gg.visit(); system("pause"); return 0; }
|