C++ DAY 5

#include 

using namespace std;

class Sofa
{
private:
    string sit;
public:
    Sofa(string s= "-") :sit(s)
    {
        cout << "sofa 构造函数" << endl;
    }
    void show ()
    {
        cout << sit << endl;
    }
};
class Bed
{
private:
    string sleep;
public:
    Bed(string a="-"):sleep(a)
    {
        cout << "bed 构造函数" << endl;
    }
    void show()
    {
        cout << sleep << endl;
    }
};
class Sofa_bed : public Sofa ,public Bed
{
private:
    string color;
public:
    Sofa_bed()
    {}
    Sofa_bed(string s ,string a ,string c) : Sofa(s) ,Bed (a) ,color(c)
    {
        cout << "Sofa_bed 构造函数" << endl;
    }
    void show()
    {
        cout << color << endl;
    }

};

int main()
{
    Sofa_bed s1("可坐" ,  "可躺" ,"blue");
    s1.Sofa::show();
    s1.Bed::show();
    s1.show();
    
    return 0;
}

你可能感兴趣的:(算法)