我正在从 stl 优先级队列创建一个最小堆.这是我正在使用的课程.
I am creating a min heap from stl priority queue. Here is my class which I am using.
class Plane { private : int id ; int fuel ; public: Plane():id(0), fuel(0){} Plane(const int _id, const int _fuel):id(_id), fuel(_fuel) {} bool operator > (const Plane &obj) { return ( this->fuel > obj.fuel ? true : false ) ; }};
在 main 中,我因此实例化了一个对象.
In main I instantiate an object thus.
priority_queue<Plane*, vector<Plane*>, Plane> pq1 ; pq1.push(new Plane(0, 0)) ;我从 xutility 收到一个我无法理解的错误.
I am getting an error from xutility which I am unable to understand.
d:\microsoft Visual Studio 10.0\vc\include\xutility(674): error C2064: term 不计算为采用 2 个参数的函数
d:\microsoft visual studio 10.0\vc\include\xutility(674): error C2064: term does not evaluate to a function taking 2 arguments
对其解决方案的任何帮助将不胜感激.
Any help to its solution would be appreciated.
推荐答案第三个模板参数必须是一个采用 teo Plane* 的二元函子.您的 Plane 类没有提供.
The third template parameter must be a binary functor taking teo Plane*. Your Plane class does not provide that.
你需要某种形式的东西
struct CompPlanePtrs { bool operator()(const Plane* lhs, const Plane* rhs) const { return lhs->fuel > rhs->fuel ; } };更多推荐
从 STL 优先级队列创建最小堆
发布评论