当前位置:网站首页>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];
边栏推荐
猜你喜欢
[BSidesCF 2019]Kookie
token, jwt, oauth2, session parsing
YYGH-13-Customer Service Center
Increasing leetcode - a daily topic 1403. The order of the boy sequence (greed)
Open-Falcon of operation and maintenance monitoring system
Haproxy搭建Web群集
Mysql的redo log详解
商业智能BI业务分析思维:现金流量风控分析(一)营运资金风险
Leading the highland of digital medicine, Zhongshan Hospital explores to create a "new paradigm" for future hospitals
日志导致线程Block的这些坑,你不得不防
随机推荐
UE4 为子弹蓝图添加声音和粒子效果
How to find all fields with empty data in sql
What is the difference between SAP ERP and ORACLE ERP?
Redis key basic commands
Event parse tree Drain3 usage and explanation
冰蝎V4.0攻击来袭,安全狗产品可全面检测
public static
List asList(T... a) What is the prototype? 【8.1】代码源 - 【第二大数字和】【石子游戏 III】【平衡二叉树】
token, jwt, oauth2, session parsing
JeeSite新建报表
Redis1: Introduction to Redis, basic features of Redis, relational database, non-relational database, database development stage
新人如何入门和学习软件测试?
[极客大挑战 2019]FinalSQL
The test salary is so high?20K just graduated
[SWPU2019]Web1
ffmpeg 枚举decoders, encoders 分析
YYGH-13-客服中心
presto启动成功后出现2022-08-04T17:50:58.296+0800 ERROR Announcer-3 io.airlift.discovery.client.Announcer
Developing Hololens encountered The type or namespace name 'HandMeshVertex' could not be found..
[TA-Frost Wolf_may-"Hundred Talents Project"] Graphics 4.3 Real-time Shadow Introduction