[工学]第十章 继承1
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * class Bed : public Furniture{ public: Bed(){} void sleep()const{ cout Sleeping...\n; }}; class Sofa : public Furniture{ public: Sofa(){} void watchTV()const{ cout Watching TV.\n; }}; class SleeperSofa : public Bed, public Sofa{ public: SleeperSofa() :Sofa(), Bed(){} void FoldOut()const{ cout Fold out the sofa.\n; }}; int main(){ SleeperSofa ss; ss.setWeight(20); // error 模糊的setWeight成员 Furniture* pF = (Furniture*)ss; // error 模糊的Furniture* coutpF-getWeight()endl;} 10.7.1 虚拟继承 程序f1007.c
原创力文档

文档评论(0)