- class Sofa
- {
- protected:
- string sit;
- public:
- Sofa()
- {
- cout << "沙发无参构造" << endl;
- }
- Sofa(string s):sit(s)
- {
- cout << "沙发有参构造" << endl;
- }
- Sofa(const Sofa &other):sit(other.sit)
- {
- cout << "沙发拷贝构造" << endl;
- }
- Sofa &operator=(const Sofa &other)
- {
- cout << "沙发拷贝赋值" << endl;
- if(this!= &other)
- {
- sit = other.sit;
- }
- return *this;
- }
- void show()
- {
- cout << "sit=" << sit <
- }
- };
-
- class Bed
- {
- protected:
- string sleep;
- public:
- Bed()
- {
- cout << "床无参构造" << endl;
- }
- Bed(string s):sleep(s)
- {
- cout << "床有参构造" << endl;
- }
- Bed(const Bed &other):sleep(other.sleep)
- {
- cout << "床拷贝构造" << endl;
- }
- Bed &operator=(const Bed &other)
- {
- cout << "床拷贝赋值" << endl;
- if(this!= &other)
- {
- sleep = other.sleep;
- }
- return *this;
- }
- void show()
- {
- cout << "sleep=" << sleep <
- }
- };
-
- class Sofa_bed:public Sofa,protected Bed
- {
- private:
- string down;
- public:
- Sofa_bed()
- {
- cout << "床和沙发的无参构造" << endl;
- }
- Sofa_bed(string a,string b,string c):Sofa(a),Bed(b),down(c)
- {
- cout << "床和沙发的有参构造" << endl;
- }
- Sofa_bed(const Sofa_bed &other):Sofa(other),Bed(other),down(other.down)
- {
- cout << "床和沙发的拷贝构造" << endl;
- }
- Sofa_bed &operator=(const Sofa_bed &other)
- {
- cout << "床和沙发的拷贝赋值" << endl;
- if(this!= &other)
- {
- down = other.down;
- Sofa::operator = (other);
- Bed::operator = (other);
- }
- return *this;
- }
- void show()
- {
- cout << "多继承子类" << endl;
- cout << "down=" << down << endl;
- cout << "sit=" << sit << endl;
- cout << "sleep=" << sleep << endl;
-
- }
- };

-
相关阅读:
HBuilderX修改manifest.json设置,解决跨域问题(CORS、Cross-Origin)
⑭霍兰德RS*型如何选专业?高考志愿填报选专业
Java -- 每日一问:谈谈 Spring Bean 的生命周期和作用域?
JSP | JSP的page指令和九大内置对象
C语言实现B树算法
【云计算网络安全】解析DDoS攻击:工作原理、识别和防御策略 | 文末送书
Centos7安装Nginx
【uniapp】自定义导航栏时,设置安全距离,适配不同机型
微信小程序--WXML模板(页面逻辑)-2
Matplotlib绘制动图以及绘制平滑曲线
-
原文地址:https://blog.csdn.net/m0_73912044/article/details/133777113