文章目录
重载<
struct node {
int first;
int second;
friend bool operator<(const struct node& a, const struct node& b) {
if (a.first < b.first ||
(a.first == b.first && a.second < b.second)) {
return true;
}
return false;
}
};
最重要的地方就是这个对<
的重载了,这是为map内部排序定规则,以何种大小顺序插值。否则就会报错error: no match for 'operator<' (operand types are 'const node' and 'const node')