我试图使用自定义比较器按值排序地图,但我无法弄清楚为什么我一直收到“没有匹配的 compareByVal 调用”的错误
这是我在 main.cpp 中的内容:
#include <map>
#include <iostream>
struct compareByVal {
bool operator[](const std::pair<int,int> & a, const std::pair<int,int> & b)
return a.second < b.second;
}
int main() {
std::map<int,int,compareByVal> hash;
hash[1] = 5;
hash[2] = 2;
hash[3] = 10;
std::cout << hash.begin()->first << std::endl;
}