当前位置:网站首页>重载运算符
重载运算符
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];边栏推荐
- Queue Topic: Recent Requests
- 银行数据采集,数据补录与指标管理3大问题如何解决?
- GC Gaode coordinate and Baidu coordinate conversion
- Increasing leetcode - a daily topic 1403. The order of the boy sequence (greed)
- Redis key basic commands
- rpc-remote procedure call demo
- UE4 通过互动(键盘按键)开门
- 多御安全浏览器 V10.8.3.1 版正式发布,优化多项内容
- Web3.0 Dapps——通往未来金融世界的道路
- Android interview question - how to write with his hands a non-blocking thread safe queue ConcurrentLinkedQueue?
猜你喜欢

UE4 第一人称角色模板 添加生命值和调试伤害

数据库设计的酸(ACID)碱(BASE)原则

Static method to get configuration file data

UE4 第一人称角色模板 添加冲刺(加速)功能

UE4 opens doors with overlapping events

There are several common event handling methods in Swing?How to listen for events?

Walter talked little knowledge | "remote passthrough" that something

Shell script: for loop and the while loop

iMedicalLIS listener (2)

银行数据采集,数据补录与指标管理3大问题如何解决?
随机推荐
Detailed and comprehensive postman interface testing practical tutorial
Redis key basic commands
Initial solution of the structure
Android interview question - how to write with his hands a non-blocking thread safe queue ConcurrentLinkedQueue?
UE4 更改组件变量 (以修改第一人称角色模板的最大行走速度和跳跃高度为例)
将故事写成我们
GC Gaode coordinate and Baidu coordinate conversion
UE4 为子弹蓝图添加声音和粒子效果
结构体初解
新人如何入门和学习软件测试?
2022.8.4-----leetcode.1403
银行数据采集,数据补录与指标管理3大问题如何解决?
YYGH-13-客服中心
UE4 后期处理体积 (角色受到伤害场景颜色变淡案例)
shell脚本:for循环与while循环
Fifteen. Actual combat - MySQL database building table character set and collation
国学*周易*梅花易数 代码实现效果展示 - 梅花心易
iMedicalLIS监听程序(2)
UI自动化测试 App的WebView页面中,当搜索栏无搜索按钮时处理方法
Never put off till tomorrow what you can put - house lease management system based on the SSM