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

-
相关阅读:
ES:模板字符串的使用
vue中的事件处理
淘宝/天猫、1688、京东、抖音按图搜索淘宝商品(拍立淘)API接口(参数说明值)
2.6基数排序(桶排序)
机器学习算法基础--层次聚类法
Springboot多数据源配置详解
SA实战 ·《SpringCloud Alibaba实战》第11章-服务容错加餐:Sentinel核心技术与配置规则(最全使用教程)
笔训day1
唐先杰遇上区块链:要加薪,也要改变世界 | 对话MVP
PDF编辑软件pdf转word工具Acrobat DC百度云盘分享
-
原文地址:https://blog.csdn.net/m0_73912044/article/details/133777113