当前位置:网站首页>重载运算符
重载运算符
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];边栏推荐
- 商业智能BI业务分析思维:现金流量风控分析(一)营运资金风险
- You may use special comments to disable some warnings. Three ways to report errors
- Open-Falcon of operation and maintenance monitoring system
- 关于#SQL#的迭代、父子结构查询问题,如何解决?
- 十五. 实战——mysql建库建表 字符集 和 排序规则
- 达梦8数据库导出导入
- How to solve the three major problems of bank data collection, data supplementary recording and index management?
- 事件解析树Drain3使用方法和解释
- [Solved] Unity Coroutine coroutine is not executed effectively
- You may use special comments to disable some warnings. 报错解决的三种方式
猜你喜欢

Static method to get configuration file data

多列属性column元素的可见性:display、visibility、opacity、垂直对齐方式:vertical-align、z-index 越大越显示在上层

七夕节代码表白

Use CH341A to program external Flash (W25Q16JV)

将故事写成我们

【Mysql进阶优化篇02】索引失效的10种情况及原理

2022-08-04T17:50:58.296+0800 ERROR Announcer-3 io.airlift.discovery.client.Announcer appears after successful startup of presto

The second council meeting of the Dragon Lizard Community was successfully held!Director general election, 4 special consultants joined

Web3.0 Dapps——通往未来金融世界的道路

Ice Scorpion V4.0 attack, security dog products can be fully detected
随机推荐
新人如何入门和学习软件测试?
多列属性column元素的可见性:display、visibility、opacity、垂直对齐方式:vertical-align、z-index 越大越显示在上层
Spark Basics [Introduction, Getting Started with WordCount Cases]
Haproxy搭建Web群集
用Unity发布APP到Hololens2无坑教程
Package zip is not available, but is referred to by another package.
达梦8数据库导出导入
【树莓派】树莓派调光
35岁的软件测试工程师,月薪不足2W,辞职又怕找不到工作,该何去何从?
Event parse tree Drain3 usage and explanation
From "useable" to "easy to use", domestic software is self-controllable and continues to advance
YYGH-13-Customer Service Center
UE4 为子弹蓝图添加声音和粒子效果
Redis key基本命令
Acid (ACID) Base (BASE) Principles for Database Design
Android interview question - how to write with his hands a non-blocking thread safe queue ConcurrentLinkedQueue?
Hard power or soft power, which is more important to testers?
冰蝎V4.0攻击来袭,安全狗产品可全面检测
Why is the pca component not associated
DEJA_VU3D - Cesium功能集 之 058-高德地图纠偏