f1006.cpp

来自「it is a usefull thing」· C++ 代码 · 共 36 行

CPP
36
字号
//=====================================
// 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();
}//====================================

 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?