ch17_3.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:
C#编程
开发平台:
Visual C++
- //**********************
- //** ch17_3.cpp **
- //**********************
- #include<iostream.h>
- class Furniture{
- public:
- Furniture(){}
- void SetWeight(int i){ weight =i; }
- int GetWeight(){ return weight; }
- protected:
- int weight;
- };
- class Bed :virtual public Furniture{
- public:
- Bed(){}
- void Sleep(){ cout <<"Sleeping...n"; }
- };
- class Sofa :virtual 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);
- cout <<ss.GetWeight() <<endl;
- }