我必须将无序映射传递给优先级队列的比较器函数,并使用链接将参数传递给比较函数?我决定这样做如下:
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)
为的构造函数priority_queue
的参数,并将其指定compare
为类型模板的参数。
priority_queue < int, std::vector<int>, compare> pq{compare(freq)};
// ^^^^^^^ ^^^^^^^^^^^^^^^
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句