c ++ stl priority_queue,自定义比较器作为函数参数

时间:2012-11-29 21:36:15

标签: c++ stl priority-queue

我想使用priority_queue并将其传递给函数:

// compare points according their distance to some target point
struct MyComparator {
    Point target;
    MyComparator(Point t) : target(t) {}

    bool operator() (const Point& p1, const Point& p2) {
         return distance(target, p1) < distance(target, p2);
    }
};

typedef priority_queue<Point, vector<Point>, MyComparator> myque;
void myfunc(const Point& target, myque& que) { ... }

// call myfunc
Point target = ...;
myque queue(MyComparator(target));
myfunc(target, queue); 
// error :
no matching function for call to ‘myfunc(const Point&, myque (&)(MyComparator))’

如何解决此错误?

感谢。

0 个答案:

没有答案