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

10.11作业

多继承代码实现沙发床

#include <iostream>using namespace std;class Sofa {private:int h;public:Sofa() {cout << "Sofa无参构造" << endl;}Sofa(int h): h(h) {cout << "Sofa有参构造" << endl;}Sofa(const Sofa& other): h(other.h) {cout << "Sofa拷贝构造" << endl;}Sofa& operator=(const Sofa& other) {cout << "Sofa赋值拷贝" << endl;h = other.h;return *this;}~Sofa() {cout << "Sofa析构函数" << endl;}
};
class Bad {private:int w;public:Bad() {cout << "Bad无参构造" << endl;}Bad(int w): w(w) {cout << "Bad有参构造" << endl;}Bad(const Bad& other): w(other.w) {cout << "Bad拷贝构造" << endl;}Bad& operator=(const Bad& other) {cout << "Bad赋值拷贝" << endl;w = other.w;return *this;}~Bad() {cout << "Bad析构函数" << endl;}
};
class Sofa_Bad: public Sofa, protected Bad {private:string name;public:Sofa_Bad() {cout << "Sofa_Bad无参构造" << endl;}Sofa_Bad(string name, int h, int w): Sofa(h), Bad(w), name(name) {cout << "Sofa_Bad有参构造" << endl;}Sofa_Bad(const Sofa_Bad& other): Sofa(other), Bad(other), name(other.name) {cout << "Sofa_Bad拷贝构造" << endl;}Sofa_Bad& operator=(const Sofa_Bad& other) {Sofa::operator=(other);Bad::operator=(other);name = other.name;cout << "Sofa_Bad赋值拷贝" << endl;return *this;}~Sofa_Bad() {cout << "Sofa_Bad析构函数" << endl;}
};
int main() {Sofa_Bad s1;Sofa_Bad s2("aaaa", 100, 200);Sofa_Bad s3(s2);s1 = s3;return 0;
}

http://www.lryc.cn/news/188944.html

相关文章:

  • 如何对比github中不同commits的区别
  • 串的基本操作(数据结构)
  • ctfshow-web12(glob绕过)
  • hive3.1核心源码思路
  • LATR:3D Lane Detection from Monocular Images with Transformer
  • 什么是UI自动化测试工具?
  • 计算顺序表中值在100到500之间的元素个数
  • 【问题总结】级数的括号可以拆吗?
  • 抖音自动养号脚本+抖音直播控场脚本
  • uvm中transaction的response和id的解读
  • 第四节(1):EXCEL中判断一个WORD文件是否被打开
  • java.util.concurrent.locks.Condition详解
  • 选择适合变更管理的产品开发工具的要点和建议
  • 小程序 词云图 echarts-for-weixin-wordcloud
  • VScode配置Jupyter
  • java模拟GPT流式问答
  • 【好玩】如何在github主页放一条贪吃蛇
  • 顶顶通ASR安装配置说明
  • VMware和别的服务器 ,组建局域网那些事 。
  • 自监督DINO论文笔记
  • 计算机视觉: 基于隐式BRDF自编码器的文生三维技术
  • 分类预测 | MATLAB实现KOA-CNN-BiLSTM开普勒算法优化卷积双向长短期记忆神经网络数据分类预测
  • Java队列相关面试题
  • 水库大坝除险加固安全监测系统解决方案
  • android native C++编程实现数据库加密sqlcipher
  • 第五节 C++ 循环结构(算法)
  • 接口与抽象类的区别
  • 短视频账号矩阵系统源码saas===独立部署
  • 香港专用服务器拥有良好的国际网络连接
  • IP/SIP网络有源吸顶喇叭 20W扬声器 可供POE供电