今日任务
1> 思维导图
2> 多继承代码实现沙发床
代码:
#include <iostream>
using namespace std;
class Sofa
{
private:
string sitting;
public:
Sofa() {}
Sofa(string s):sitting(s){
cout << "Sofa 有参" <<endl;
}
void show(){
cout << "sofa show" << sitting <<endl;
}
};
class Bed
{
private:
string sleep;
public:
Bed() {}
Bed(string s):sleep(s){
cout << "Bed 有参" <<endl;
}
void show(){
cout << "Bed show"<< sleep << endl;
}
};
class SofaBed:public Sofa,public Bed{
private:
string everything;
public:
SofaBed(){}
SofaBed(string sitting,string sleep,string everything):Sofa(sitting),Bed(sleep),everything(everything){
cout << "SofaBed 有参" <<endl;
}
};
int main()
{
SofaBed s=SofaBed("sit..","sle...","eve...");
s.Bed::show();
s.Sofa::show();
return 0;
}
运行结果:
今日思维导图