C++DAY43

C++DAY43_第1张图片 

#include 

using namespace std;

//封装 沙发 类
class Sofa
{
private:
    string living;
public:
    Sofa(){cout << "沙发的无参构造函数" << endl;}
    Sofa(string l):living(l)
    {
        cout << "沙发的有参构造函数" << endl;
    }

    void show()
    {
        cout << living << endl;
    }
};

//封装 电视 类
class Tv
{
private:
    string see;
public:
    Tv(){cout << "电视的无参构造函数" << endl;}
    Tv(string s):see(s)
    {
        cout << "电视的有参构造函数" << endl;
    }

    void show()
    {
        cout << see << endl;
    }
};

//封装 沙发电视 类 共有继承于沙发和电视类
class Sofa_Tv :public Sofa,public Tv
{
private:
    string color;
public:
    Sofa_Tv(){cout << "沙发电视的无参构造函数" << endl;}
    Sofa_Tv(string s,string t,string c):Sofa(s),Tv(t),color(c)
    {
        cout << "沙发电视的有参构造函数" << endl;
    }
};

int main()
{
    Sofa_Tv s("可坐","可看","black");
    s.Sofa::show();
    s.Tv::show();
    return 0;
}

 

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