#include <iostream>
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;
}
C++ DAY 5
最新推荐文章于 2024-07-10 16:47:58 发布