(一)代码
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 }
解析:Sofabed继承了Sofa和bed类的功能