我在使用优先队列时遇到了很多麻烦,无法让它识别应该按哪个参数进行排序。我已经在自定义类中重载了小于运算符,但似乎没有使用它。以下是相关代码:
Node.h
class Node
{
public:
Node(...);
~Node();
bool operator<(Node &aNode);
...
}
Node.cpp
#include "Node.h"
bool Node::operator<(Node &aNode)
{
return (this->getTotalCost() < aNode.getTotalCost());
}
getTotalCost() 返回一个整数(int)。
main.cpp
priority_queue<Node*, vector<Node*>,less<vector<Node*>::value_type> > nodesToCheck;
我错过了什么?或者我做错了什么?