我不得不将无序映射传递给优先级队列的比较器功能,并使用链接Passing a parameter to a comparison function?,我决定如下进行操作:
priority_queue < int, std::vector<int>, compare(freq) > pq;
struct compare
{
compare( std::unordered_map<int,int>& freq1 )
{
freq = freq1;
}
bool operator()( int& el1, int& el2 ){
return freq[el1] < freq[el2];
}
std::unordered_map<int,int> freq;
};
但是我遇到错误:
Template argument for template type parameter must be a type
我在做什么错?
正如错误消息所述,compare(freq)
不是类型,不能将其指定为类型模板参数。
您应将compare(freq)
指定为constructor of priority_queue
的参数,并指定priority_queue
作为类型模板的参数。
compare