当前位置:网站首页>重载运算符
重载运算符
2022-08-05 03:53:00 【Codiplay】
struct student {
string name;
int score;
bool operator<(const student& a) const {
return score < a.score || (score == a.score && name > a.name);
// 上面省略了 this 指针,完整表达式如下:
// this->score<a.score||(this->score==a.score&&this->name>a.name);
}
};
priority_queue<student> pq;
上面的代码将小于号重载为了成员函数,当然重载为非成员函数也是可以的。
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<student> pq;
构造函数等价于c++里面 { }
如果要开数组,需要加上 = 0作为初始化
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];
边栏推荐
- ffmpeg 像素格式基础知识
- public static
List asList(T... a) What is the prototype? - Android实战开发-Kotlin教程(入门篇-登录功能实现 3.3)
- 【Mysql进阶优化篇02】索引失效的10种情况及原理
- UE4 opens door via interaction (keyboard key)
- Event parse tree Drain3 usage and explanation
- 不看后悔,appium自动化环境完美搭建
- There are several common event handling methods in Swing?How to listen for events?
- Redis1: Introduction to Redis, basic features of Redis, relational database, non-relational database, database development stage
- Mathematics - Properties of Summation Symbols
猜你喜欢
After the large pixel panorama is completed, what are the promotion methods?
Detailed and comprehensive postman interface testing practical tutorial
[Software testing] unittest framework for automated testing
UE4 在游戏运行时更改变量 (通过鼠标滑轮来更改第一人称角色的最大行走速度)
日志导致线程Block的这些坑,你不得不防
Web3.0 Dapps——通往未来金融世界的道路
mutillidae下载及安装
Android interview question - how to write with his hands a non-blocking thread safe queue ConcurrentLinkedQueue?
多御安全浏览器新版下载 | 功能优秀性能出众
36-Jenkins-Job Migration
随机推荐
Increasing leetcode - a daily topic 1403. The order of the boy sequence (greed)
DEJA_VU3D - Cesium功能集 之 057-百度地图纠偏
结构体初解
The test salary is so high?20K just graduated
Walter talked little knowledge | "remote passthrough" that something
public static <T> List<T> asList(T... a) 原型是怎么回事?
多御安全浏览器 V10.8.3.1 版正式发布,优化多项内容
UE4 后期处理体积 (角色受到伤害场景颜色变淡案例)
UE4 为子弹蓝图添加声音和粒子效果
2022.8.4-----leetcode.1403
Index Mysql in order to optimize paper 02 】 【 10 kinds of circumstances and the principle of failure
What is the difference between SAP ERP and ORACLE ERP?
UE4 第一人称角色模板 添加生命值和调试伤害
惨遭打脸:字节某部门竟有这么多测试员
Bubble Sort and Quick Sort
Fifteen. Actual combat - MySQL database building table character set and collation
如何解决复杂的分销分账问题?
国学*周易*梅花易数 代码实现效果展示 - 梅花心易
测试薪资这么高?刚毕业就20K
新人如何入门和学习软件测试?