
- #include
-
- using namespace std;
-
- class Sofa
- {
- private:
- string sit;
- public:
- Sofa()
- {
- cout << "调用沙发的无参构造函数" << endl;
- }
- Sofa(string s):sit(s)
- {
- cout << "调用沙发的有参构造函数" << endl;
- }
- ~Sofa()
- {
- cout<< "调用沙发的析构函数" << endl;
- }
- void show()
- {
- cout << sit << endl;
- }
- };
-
- class Bed
- {
- private:
- string sleep;
- public:
- Bed()
- {
- cout << "调用床的无参构造函数" << endl;
- }
- Bed(string s):sleep(s)
- {
- cout << "调用床的有参构造函数" << endl;
- }
- ~Bed()
- {
- cout << "调用床的析构函数" <
- }
- void show()
- {
- cout << sleep << endl;
- }
- };
-
- class Sofa_Bed:public Sofa,public Bed
- {
- private:
- string color;
- public:
- Sofa_Bed()
- {
- cout << "调用沙发床的无参构造函数" << endl;
- }
- Sofa_Bed(string sit,string sleep,string color):Sofa(sit),Bed(sleep),color(color)
- {
- cout << "调用沙发床的有参构造函数" << endl;
- }
- ~Sofa_Bed()
- {
- cout << "调用沙发床的析构函数" << endl;
- }
- void show()
- {
- Sofa::show();
- Bed::show();
- cout << color << endl;
- }
- };
-
- int main()
- {
- Sofa_Bed s1("可坐","可躺","dark");
- s1.show();
- return 0;
- }