我使用 STLpriority_queue
并提供一个自定义比较器类,其构造函数接收指向存储优先级的向量的指针,因此 -
#include <iostream>
#include <queue> // std::priority_queue
#include <vector> // std::vector
using namespace std;
class CompareReachDist
{
const vector<float> *reach_dists;
public:
CompareReachDist(const vector<float> *input)
{
reach_dists = input;
}
bool operator() (const size_t &l, const size_t &r) const
{
return (reach_dists->at(l) > reach_dists->at(r));
}
};
typedef priority_queue<size_t, vector<size_t>, CompareReachDist> pq;
vector<float> reach_dists;
int main()
{
pq seeds(CompareReachDist(&reach_dists));
bool isEmpty = seeds.empty();
return 0;
}
但是,在编译时出现错误:
error: request for member 'empty' in 'seeds', which is of non-class type 'pq(CompareReachDist&) {aka std::priority_queue<unsigned int std::vector<unsigned int>, CompareReachDist>(CompareReachDist&)}'
我哪里错了?