当前位置:网站首页>重载运算符
重载运算符
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];
边栏推荐
- 【测量学】速成汇总——摘录高数帮
- UE4 第一人称角色模板 添加蹲伏功能
- Bubble Sort and Quick Sort
- UE4 通过与其它Actor互动开门
- 数据库设计的酸(ACID)碱(BASE)原则
- Use CH341A to program external Flash (W25Q16JV)
- Acid (ACID) Base (BASE) Principles for Database Design
- Redis key basic commands
- Developing Hololens encountered The type or namespace name 'HandMeshVertex' could not be found..
- 将故事写成我们
猜你喜欢
Swing有几种常用的事件处理方式?如何监听事件?
多御安全浏览器新版下载 | 功能优秀性能出众
炎炎夏日教你利用小米智能家居配件+树莓派4接入Apple HomeKit
MRTK3 develops Hololens application - gesture drag, rotate, zoom object implementation
UE4 第一人称角色模板 添加冲刺(加速)功能
UE4 后期处理体积 (角色受到伤害场景颜色变淡案例)
[Filter tracking] based on matlab unscented Kalman filter inertial navigation + DVL combined navigation [including Matlab source code 2019]
用Unity发布APP到Hololens2无坑教程
YYGH-13-客服中心
The most effective seven performance testing techniques of software testing techniques
随机推荐
【背包九讲——01背包问题】
Index Mysql in order to optimize paper 02 】 【 10 kinds of circumstances and the principle of failure
Swing有几种常用的事件处理方式?如何监听事件?
Android Practical Development - Kotlin Tutorial (Introduction - Login Function Implementation 3.3)
UE4 第一人称角色模板 添加冲刺(加速)功能
Redis key基本命令
[Paper Notes] MapReduce: Simplified Data Processing on Large Clusters
pyqt5 + socket 实现客户端A经socket服务器中转后主动向客户端B发送文件
rpc-remote procedure call demo
开发Hololens遇到The type or namespace name ‘HandMeshVertex‘ could not be found..
[论文笔记] MapReduce: Simplified Data Processing on Large Clusters
惨遭打脸:字节某部门竟有这么多测试员
cross domain solution
presto启动成功后出现2022-08-04T17:50:58.296+0800 ERROR Announcer-3 io.airlift.discovery.client.Announcer
Slapped in the face: there are so many testers in a certain department of byte
Hard power or soft power, which is more important to testers?
MySql的索引学习和使用;(本人觉得足够详细)
Bubble Sort and Quick Sort
Redis key basic commands
Package zip is not available, but is referred to by another package.