C++&QT-day5

#include     //多继承

using namespace std;

class Sofa
{
private:
    string sitting;
public:
    Sofa()
    {
        cout << "Sofa无参构造函数" << endl;
    }
    Sofa(string sitting):sitting(sitting)
    {
        cout << "Sofa有参构造函数" << endl;
    }
    void show()
    {
        cout << sitting << " ";
    }
};
class Bed
{
private:
    string sleep;
public:
    Bed()
    {
        cout << "Bed无参构造函数" << endl;
    }
    Bed(string sleep):sleep(sleep)
    {
        cout << "Bed有参构造函数" << endl;
    }
    void show()
    {
        cout << sleep << " ";
    }
};

class Sofa_Bed:public Sofa,public Bed
{
private:
    string color;
public:
    Sofa_Bed()
    {
        cout << "Sofa_Bed无参构造函数" << endl;
    }
    Sofa_Bed(string sitting, string sleep, string color):Sofa(sitting),Bed(sleep),color(color)
    {
        cout << "Sofa_Bed有参构造函数" << endl;
    }
    void show()
    {
        cout << color << endl;
    }

};
int main()
{
    Sofa_Bed s1;
    Sofa_Bed s("坐","躺","白");
    s.Sofa::show();
    s.Bed::show();
    s.Sofa_Bed::show();
    return 0;
}

C++&QT-day5_第1张图片

C++&QT-day5_第2张图片

你可能感兴趣的:(c++,qt,开发语言)