ch17_2.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:
C#编程
开发平台:
Visual C++
- //**********************
- //** ch17_2.cpp **
- //**********************
- #include<iostream.h>
- class Furniture{
- public:
- Furniture(){}
- void SetWeight(int i){ weight =i; }
- int GetWeight(){ return weight; }
- protected:
- int weight;
- };
- class Bed :public Furniture{
- public:
- Bed(){}
- void Sleep(){ cout <<"Sleeping...n"; }
- };
- class Sofa :public Furniture{
- public:
- Sofa(){}
- void WatchTV(){ cout <<"Watching TV.n"; }
- };
- class SleeperSofa :public Bed, public Sofa{
- public:
- SleeperSofa() :Sofa(), Bed(){}
- void FoldOut(){ cout <<"Fold out the sofa.n"; }
- };
- void main()
- {
- SleeperSofa ss;
- ss.SetWeight(20); //编译出错!模糊的SetWeight成员
- Furniture* pF;
- pF =(Furniture*)&ss; //编译出错!模糊的Furniture*
- cout <<pF->GetWeight() <<endl;
- }