当前位置:网站首页>overloaded operator
overloaded operator
2022-08-05 03:59:00 【Codiplay】
struct student {string name;int score;bool operator<(const student& a) const {return score < a.score || (score == a.score && name > a.name);// The this pointer is omitted above, the full expression is as follows:// this->scorescore==a.score&&this->name>a.name);}};priority_queue pq;
The above code overloads the less than sign as a member function, of course, it is also possible to overload it as a non-member function.
struct student {string name;int score;};bool operator<(const student& a, const student& b) {return a.score < b.score || (a.score == b.score && a.name > b.name);}priority_queue pq;
Constructor is equivalent to { } in C++
If you want to open an array, you need to add = 0 as initialization
struct Queue {int num, id;Queue(int _num = 0, int _id = 0) :num(_num), id(_id) {}bool operator < (const Queue &t) const {if(num == t.num) return id < t.id;return num < t.num;}}q[N];
边栏推荐
- How to discover a valuable GameFi?
- BI业务分析思维:现金流量风控分析(二)信用、流动和投资风险
- Qixi Festival code confession
- 【8.1】代码源 - 【第二大数字和】【石子游戏 III】【平衡二叉树】
- pyqt5 + socket 实现客户端A经socket服务器中转后主动向客户端B发送文件
- How do newcomers get started and learn software testing?
- Slapped in the face: there are so many testers in a certain department of byte
- Growth-based checkerboard corner detection method
- The test salary is so high?20K just graduated
- C+ +核心编程
猜你喜欢
Use CH341A to program external Flash (W25Q16JV)
阿里本地生活单季营收106亿,大文娱营收72亿,菜鸟营收121亿
leetcode-每日一题1403. 非递增顺序的最小子序列(贪心)
Open-Falcon of operation and maintenance monitoring system
多御安全浏览器 V10.8.3.1 版正式发布,优化多项内容
工业级远距离无线传输装置的功能有哪些?
日志导致线程Block的这些坑,你不得不防
Mysql的redo log详解
[Software testing] unittest framework for automated testing
bytebuffer 内部结构
随机推荐
队列题目:最近的请求次数
Initial solution of the structure
[SWPU2019]Web1
905. Interval selection
Bosses, I noticed that a mysql CDC connector parameters scan. The incremental. Sna
ffmpeg 枚举decoders, encoders 分析
The test salary is so high?20K just graduated
Paparazzi: Surface Editing by way of Multi-View Image Processing
UE4 第一人称角色模板 添加生命值和调试伤害
ffmpeg pixel format basics
Spark基础【介绍、入门WordCount案例】
BI业务分析思维:现金流量风控分析(二)信用、流动和投资风险
Open-Falcon of operation and maintenance monitoring system
How to wrap markdown - md file
第一次性能测试实践,有“亿”点点紧张
Call Alibaba Cloud oss and sms services
Fifteen. Actual combat - MySQL database building table character set and collation
Increasing leetcode - a daily topic 1403. The order of the boy sequence (greed)
多御安全浏览器 V10.8.3.1 版正式发布,优化多项内容
ffmpeg -sources分析