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

12.04

#include <iostream>using namespace std;class Sofa
{
private:string sitting;double *weight;
public:Sofa(){cout << "Sofa::无参构造函数" << endl;}Sofa(string s,double w):sitting(s),weight(new double(w)){cout << "Sofa::有参构造函数" << endl;}Sofa(const Sofa &other):sitting(other.sitting),weight(new double(*(other.weight))){cout << "Sofa::拷贝构造函数" << endl;}Sofa &operator=(const Sofa &other){if(this!=&other){sitting = other.sitting;weight = new double(*(other.weight));}cout << "Sofa::拷贝赋值函数" << endl;return *this;}~Sofa(){cout << "Sofa::析构函数" << endl;delete weight;}void show(){cout << "sitting = " << sitting << endl;cout << "weight = " << weight<< endl;}
};
class Bed
{
private:string sleep;
public:Bed(){cout << "Bed::无参构造函数" << endl;}Bed(string sl):sleep(sl){cout << "Bed::有参构造函数" << endl;}Bed(const Bed &other):sleep(other.sleep){cout << "Bed::拷贝构造函数" << endl;}Bed &operator=(const Bed &other){if(this!=&other){sleep = other.sleep;}cout << "Bed::拷贝赋值函数" << endl;return *this;}~Bed(){cout << "Bed::析构函数" << endl;}void show(){cout << "sleep = " << sleep << endl;}
};
class SofaBed:public Sofa,public Bed
{
private:string color;
public:SofaBed(){cout << "SofaBed::无参构造函数" << endl;}SofaBed(string s,double w,string sl,string c):Sofa(s,w),Bed(sl),color(c){cout << "SofaBed::有参构造函数" << endl;}SofaBed(const SofaBed &other):Sofa(other),Bed(other),color(other.color){cout << "SofaBed::拷贝构造函数" << endl;}SofaBed &operator=(const SofaBed &other){if(this!=&other){color = other.color;Sofa::operator=(other);Bed::operator=(other);}cout << "SofaBed::拷贝赋值函数" << endl;return *this;}~SofaBed(){cout << "SofaBed::析构函数" << endl;}
};int main()
{SofaBed s("坐着",70.0,"睡着","black");s.Sofa::show();s.Bed::show();return 0;
}

相关文章:

  • 破解app思路
  • VSCode Vue 开发环境配置
  • MYSQL练题笔记-高级查询和连接-简单题3题
  • 深入了解Java Duration类,对时间的精细操作
  • 初试占比7成!只考一门数据结构+学硕复录比1:1的神仙学校,大连交通大学考情分析
  • 【C语言】扫雷小游戏初学者版
  • 实体类转SQL工具类
  • 【小程序】02-项目的基本组成
  • 【网络安全】用永恒之蓝(Eternal blue)测试windows系统的安全性
  • Vue3使用阿里云OSS直传
  • oracle FUNCTION(任意两个时间 之间的工作小时)
  • 设计模式基础(1)
  • 一键式紧急报警柱系统
  • 翻硬币(第四届蓝桥杯省赛C++B组)(java版)
  • docker compose 搭建reids集群 1主2从架构
  • 【comparator, comparable】小总结
  • 【前端学习】-粗谈选择器
  • Brief introduction of how to 'Call, Apply and Bind'
  • create-react-app做的留言板
  • java 多线程基础, 我觉得还是有必要看看的
  • nginx(二):进阶配置介绍--rewrite用法,压缩,https虚拟主机等
  • php的插入排序,通过双层for循环
  • Redux 中间件分析
  • Spark RDD学习: aggregate函数
  • tweak 支持第三方库
  • vue和cordova项目整合打包,并实现vue调用android的相机的demo
  • 成为一名优秀的Developer的书单
  • 个人博客开发系列:评论功能之GitHub账号OAuth授权
  • 区块链将重新定义世界
  • 如何用vue打造一个移动端音乐播放器
  • 使用 Xcode 的 Target 区分开发和生产环境
  • 使用Tinker来调试Laravel应用程序的数据以及使用Tinker一些总结
  • 我是如何设计 Upload 上传组件的
  • 小程序开发中的那些坑
  • 携程小程序初体验
  • puppet连载22:define用法
  • ​什么是bug?bug的源头在哪里?
  • "无招胜有招"nbsp;史上最全的互…
  • ###STL(标准模板库)
  • #微信小程序(布局、渲染层基础知识)
  • #我与Java虚拟机的故事#连载15:完整阅读的第一本技术书籍
  • (2015)JS ES6 必知的十个 特性
  • (AtCoder Beginner Contest 340) -- F - S = 1 -- 题解
  • (Matlab)使用竞争神经网络实现数据聚类
  • (附源码)ssm考试题库管理系统 毕业设计 069043
  • (四)Linux Shell编程——输入输出重定向
  • (四)Tiki-taka算法(TTA)求解无人机三维路径规划研究(MATLAB)
  • (转载)VS2010/MFC编程入门之三十四(菜单:VS2010菜单资源详解)
  • *上位机的定义
  • .NET 中使用 Mutex 进行跨越进程边界的同步
  • .NET的微型Web框架 Nancy
  • .NET运行机制
  • []AT 指令 收发短信和GPRS上网 SIM508/548
  • [20171102]视图v$session中process字段含义
  • [Android]一个简单使用Handler做Timer的例子