简体   繁体   中英

adding nodes to pirority queue(invalid operands to binary expression)

I want to add nodes to my priority queue. but however I am having an error

Invalid operands to binary expression(const node and const node)

my code

#include <queue> 
#include <iostream>

struct node
{
    int level;
    int weight;
    int profit;
    float bound;
};

int main()
{
     std::priority_queue<node> pQueue;
     node firstNode;
     pQueue.push(firstNode);
}

What should I do to resolve this error? please help thanks.

Your item type node needs an operator < for the priority queue to work. Alternatively, you can pass a comparison method to the queue on declaration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM