f1006.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:
C#编程
开发平台:
Visual C++
- //=====================================
- // f1006.cpp
- // 多重继承
- //=====================================
- #include<iostream>
- using namespace std;
- //-------------------------------------
- class Bed{
- protected:
- int weight;
- public:
- Bed():weight(0){}
- void sleep()const{ cout <<"Sleeping...n"; }
- void setWeight(int i){ weight =i; }
- };//-----------------------------------
- class Sofa{
- protected:
- int weight;
- public:
- Sofa():weight(0){}
- void watchTV()const{ cout <<"Watching TV.n"; }
- void setWeight(int i){ weight =i; }
- };//-----------------------------------
- class SleeperSofa : public Bed, public Sofa{
- public:
- SleeperSofa(){}
- void foldOut()const{ cout <<"Fold out the sofa.n"; }
- };//-----------------------------------
- int main(){
- SleeperSofa ss;
- ss.watchTV();
- ss.foldOut();
- ss.sleep();
- }//====================================