我正在尝试将一对值存储在优先队列中,并使用比较函数来比较每个对的第二个值。
#include<iostream>
#include<queue>
#include<utility>
using namespace std;
class CompareDist
{
public:
bool operator()(pair<int,int> n1,pair<int,int> n2) {
return n1.second>n2.second;
}
};
int main()
{
priority_queue<pair<int,int>,CompareDist> pq;
}
当我编译这个程序时,出现了错误。
error: no type named ‘value_type’ in ‘class CompareDist’
可能的原因是什么。我对STL很新。