- 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;
-
- }
- };

-
相关阅读:
log4j2同步日志引发的性能问题 | 京东物流技术团队
【名词解释】concolic testing和instrumentation
第六十天 周期总结及下周期计划
(13.3)Latex参考文献引用及常规引用
(CVPR 2019) PointConv: Deep Convolutional Networks on 3D Point Clouds
Redis缓存穿透、缓存击穿、缓存雪崩详解
redis-5.0.8主从集群搭建、不重启修改配置文件
软件测试分析流程及输出项包括哪些内容?
TDengine 3.0 数据订阅功能的“独家”使用经验,只此一份!
计算机网络介绍
-
原文地址:https://blog.csdn.net/m0_73912044/article/details/133777113