016_linuxC++之_多重继承

(一)代码

 1 #include <iostream>
 2 #include <string.h>
 3 #include <unistd.h>
 4 
 5 using namespace std;
 6 
 7 class Sofa {
 8 public:
 9     void watchTV(void) { cout<<"watch TV"<<endl; }
10 };
11 
12 class Bed {
13 public:
14     void sleep(void) { cout<<"sleep"<<endl; }
15 };
16 
17 class Sofabed : public Sofa, public Bed {
18 };
19 
20 int main(int argc, char **argv)
21 {
22     Sofabed s;
23     s.watchTV();
24     s.sleep();
25     return 0;
26 }
View Code

解析:Sofabed继承了Sofa和bed类的功能

posted @ 2018-09-24 15:44  陆小果哥哥  阅读(99)  评论(0编辑  收藏  举报