码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • c++day5


    1. class Sofa
    2. {
    3. protected:
    4. string sit;
    5. public:
    6. Sofa()
    7. {
    8. cout << "沙发无参构造" << endl;
    9. }
    10. Sofa(string s):sit(s)
    11. {
    12. cout << "沙发有参构造" << endl;
    13. }
    14. Sofa(const Sofa &other):sit(other.sit)
    15. {
    16. cout << "沙发拷贝构造" << endl;
    17. }
    18. Sofa &operator=(const Sofa &other)
    19. {
    20. cout << "沙发拷贝赋值" << endl;
    21. if(this!= &other)
    22. {
    23. sit = other.sit;
    24. }
    25. return *this;
    26. }
    27. void show()
    28. {
    29. cout << "sit=" << sit <
    30. }
    31. };
    32. class Bed
    33. {
    34. protected:
    35. string sleep;
    36. public:
    37. Bed()
    38. {
    39. cout << "床无参构造" << endl;
    40. }
    41. Bed(string s):sleep(s)
    42. {
    43. cout << "床有参构造" << endl;
    44. }
    45. Bed(const Bed &other):sleep(other.sleep)
    46. {
    47. cout << "床拷贝构造" << endl;
    48. }
    49. Bed &operator=(const Bed &other)
    50. {
    51. cout << "床拷贝赋值" << endl;
    52. if(this!= &other)
    53. {
    54. sleep = other.sleep;
    55. }
    56. return *this;
    57. }
    58. void show()
    59. {
    60. cout << "sleep=" << sleep <
    61. }
    62. };
    63. class Sofa_bed:public Sofa,protected Bed
    64. {
    65. private:
    66. string down;
    67. public:
    68. Sofa_bed()
    69. {
    70. cout << "床和沙发的无参构造" << endl;
    71. }
    72. Sofa_bed(string a,string b,string c):Sofa(a),Bed(b),down(c)
    73. {
    74. cout << "床和沙发的有参构造" << endl;
    75. }
    76. Sofa_bed(const Sofa_bed &other):Sofa(other),Bed(other),down(other.down)
    77. {
    78. cout << "床和沙发的拷贝构造" << endl;
    79. }
    80. Sofa_bed &operator=(const Sofa_bed &other)
    81. {
    82. cout << "床和沙发的拷贝赋值" << endl;
    83. if(this!= &other)
    84. {
    85. down = other.down;
    86. Sofa::operator = (other);
    87. Bed::operator = (other);
    88. }
    89. return *this;
    90. }
    91. void show()
    92. {
    93. cout << "多继承子类" << endl;
    94. cout << "down=" << down << endl;
    95. cout << "sit=" << sit << endl;
    96. cout << "sleep=" << sleep << endl;
    97. }
    98. };

  • 相关阅读:
    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
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号