当前位置: 首页 > article >正文

十二月四日多继承

#include <iostream>

using namespace std;
//定义沙发类
class Sofa
{
private:
    string *sitting;
public:
    Sofa(){}//无参构造函数
    Sofa(string sitting):sitting(new string (sitting))//有参构造函数
    {}
       ~Sofa()                  //析构函数
    {
        delete sitting;
    }
    Sofa &operator= (const Sofa & other)        //拷贝赋值函数
    {
        sitting=other.sitting;
        return  *this;
    }
    void show ()
    {
        cout << "沙发="<< *sitting << endl;
    }

};
//定义床类
class Bed
{
private:
    string sleep;
public:
    Bed(){}
    Bed(string sleep):sleep(sleep)
    {

    }
    ~Bed(){}
    Bed  &operator= (const Bed &other)
    {
        sleep=other.sleep;
        return *this;
    }
    void show()
    {
        cout << "床=" << sleep <<endl;
    }
};


//定义沙发床类

class Bed_Sofa:public Bed,public Sofa
{
private:
    string color;
public:
    Bed_Sofa(){}
    Bed_Sofa(string color,string sitting ,string sleep):Bed(sleep),Sofa(sitting),color(color)
    {}
    Bed_Sofa &operator=(const Bed_Sofa &other)
    {
        if(this != &other )
      {
            Sofa::operator=(other);
            Bed::operator=(other);
             this->color=other.color;
    }
        return *this;
    }
    ~Bed_Sofa()
    {

    }
    void show()
    {
        Bed::show();
        Sofa::show();
        cout <<"颜色=" << color << endl;
    }
};

int main()
{
   Bed_Sofa Bs1("green" ,"sitting","sleep");
   Bs1.show();
    return 0;
}


http://www.kler.cn/news/157340.html

相关文章:

  • 2024 年甘肃省职业院校技能大赛中职组 电子与信息类“网络安全”赛项竞赛样题-C
  • 竞赛选题YOLOv7 目标检测网络解读
  • CSS实现瀑布流
  • MyBatis 设计模式解析
  • KaiwuDB 多模数据库-时序性能优化
  • 2023经典软件测试面试题
  • 面试题目总结(二)
  • 黑马一站制造数仓实战1
  • 【自用数据结构】—将链表中的奇数全部移动到偶数前面
  • 考研英语语法(四十)
  • <Linux>(极简关键、省时省力)《Linux操作系统原理分析之存储管理(2)》(15)
  • 高效学习 React 框架AntDesign Pro
  • 玩转大数据5:构建可扩展的大数据架构
  • MySQL数据备份
  • TCP三次握手与四次挥手:推荐学习资料、过程详解、面试相关题与回答模板(为什么不是两次握手等精讲)
  • MongoDB快速入门及其SpringBoot实战
  • 网工学习7-配置 GVRP 协议
  • affinity photo和ps区别Affinity VS Ps 那个更亲民
  • 坦克大战-部分
  • 网络初识:局域网广域网网络通信基础
  • 5. 链表
  • TypeScript 的高级技巧
  • Mongodb 开启oplog,java监听oplog并写入关系型数据库
  • 一天一个设计模式---生成器模式
  • 双目测宽仪高质量生产利器
  • 网页中的json文档,怎么保存到本地
  • 强化学习Markov重要公式推导过程
  • 你好!斐波那契查找【JAVA】
  • 黑猫带你学eMMC协议第31篇:什么是eMMC的驱动强度(Drive Strength)
  • 详解FreeRTOS:软件定时器(高级篇—4)