C++ 在boost::heap::priority_队列中推送结构对象时出错

C++ 在boost::heap::priority_队列中推送结构对象时出错,c++,c++11,boost,heap,priority-queue,C++,C++11,Boost,Heap,Priority Queue,我有一个结构,其对象将被推送到boost::heap::priority\u队列中 typedef struct { int i, j; double deltaQ; } heapNode; int main() { double a[] = {0.03, 0.01, 0.04, 0.02, 0.05}; heapNode node; boost::heap::priority_queue<heapNode> maxHeap; for(i

我有一个结构,其对象将被推送到
boost::heap::priority\u队列中

typedef struct
{
  int i, j;
  double deltaQ;

} heapNode;

int main()
{
    double a[] = {0.03, 0.01, 0.04, 0.02, 0.05};
    heapNode node;

    boost::heap::priority_queue<heapNode> maxHeap;
    for(int  i = 0; i < 5; i++)
    {
        node.deltaQ = a[i];
        node.i = i;
        node.j = i;
        maxHeap.push(node);//error
    }

    for(int i = 0; i < 5; i++)
    {
        node = maxHeap.top();
        cout << node.deltaQ << " " << node.i << " " << node.j;
        cout << "\n";
        maxHeap.pop();
    }
}
typedef结构
{
int i,j;
双三角洲;
}heapNode;
int main()
{
双a[]={0.03,0.01,0.04,0.02,0.05};
heapNode节点;
boost::heap::priority\u队列maxHeap;
对于(int i=0;i<5;i++)
{
node.deltaQ=a[i];
节点i=i;
节点j=i;
maxHeap.push(节点);//错误
}
对于(int i=0;i<5;i++)
{
node=maxHeap.top();

cout您需要为
heapNode
对象提供比较操作


a) 在heapNode结构中定义
运算符需要重载运算符优先级队列必须对队列中的元素排序。为此,需要比较元素。通常使用小于运算符

error: no match for 'operator<' (operand types are 'const heapNode' and 'const heapNode')|
struct heapNode
{
  int i, j;
  double deltaQ;

  bool operator<(const heapNode& theOther) const {
      // your comparison operation
    return this->deltaQ < theOther.deltaQ;
  }
};
struct cmp {
   bool operator () (const heapNode& lhs, const heapNode& rhs) const {
     return lhs.deltaQ < rhs.deltaQ;
   }
};
cmp c;
boost::heap::priority_queue<heapNode,boost::heap::compare<cmp>> maxHeap{c};
struct HeapNode
{
  int i, j;
  double deltaQ;
  bool operator<(const HeapNode& other)
  {
     *return true if current HeapNode is less than other, else false*
  };

} heapNode;