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

2024.3.14

1.成员函数版本实现算术运算符的重载,全局函数版本实现算术运算符的重载

#include <iostream>using namespace std;class Room
{friend const Room operator-(const Room &a,const Room &b);
private:string a;int b;
public:Room(){}Room(string a,int b):a(a),b(b){}const Room operator+(const Room &other)const{Room h;h.a = other.a + this->a;h.b = other.b + this->b;return h;}void show(){cout << a << ' ' << b << endl;}
};const Room operator-(const Room &x,const Room &y)
{Room q;//q.a = x.a + y.a;q.b = x.b - y.b;return q;
}int main()
{Room m1("gxy",520);Room m2("rt",1314);Room m3 = m1+m2;m3.show();Room m4 =m1-m2;m4.show();return 0;
}

2.

 

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

相关文章:

  • chatGPT的耳朵!OpenAI的开源语音识别AI:Whisper !
  • C语言冒泡排序
  • vue2 elementui 封装一个动态表单复杂组件
  • 基于智慧灯杆的智慧城市解决方案(2)
  • 「Paraverse平行云」亮相HKSTP OPENHOUSE活动
  • CubeMX使用教程(5)——定时器PWM输出
  • superset连接Apache Spark SQL(hive)过程中的各种报错解决
  • Pulsar IO实战
  • Linux/Ubuntu/Debian基本命令:文本操作
  • Self-supervised Contextual Keyword and Keyphrase Retrieval with Self-Labelling
  • 新 树莓派4B 温湿度监测 基于debian12的树莓派OS
  • 人工智能入门之旅:从基础知识到实战应用(一)
  • GNN/GCN自己学习
  • honle电源维修UV电源控制器维修EVG EPS60
  • 【学习心得】Python好库推荐——websocket-client
  • 3.1_8 两级页表
  • 【SysBench】sysbench-1.20 命令速查表
  • neo4j网页无法打开,启动一会儿后自动关闭,查看neo4j status显示Neo4j is not running.
  • 一键卸载和安装 nvidia、cuda、cudnn、tensorrt
  • LeetCode 389. 找不同
  • 科技云报道:两会热议的数据要素,如何拥抱新技术?
  • 【linux】进程管理:进程控制块、进程号、fork创建进程、特殊进程及exec函数族解析
  • 【DL经典回顾】激活函数大汇总(八)(Maxout Softmin附代码和详细公式)
  • Docker进阶:深入了解 Dockerfile
  • 【LeetCode热题100】206. 反转链表(链表)
  • 电玩城游戏大厅计时软件怎么用,佳易王计时计费管理系统软件定时语音提醒操作教程
  • selenium也能过某数、5s盾..
  • mysql笔记:8. 视图
  • 指针的基本概念和用法
  • 工作随记:oracle重建一张1T数据量的大表