try use priority_queue. code is:
struct heapnode { int val; int row; int col; heapnode(int a, int b, int c) : val(a), row(b), col(c) {} }; class mycomparator { public: bool operator()(heapnode &n1, heapnode &n2) { return n1.val < n2.val; } }; void myfunction() { std::priority_queue<heapnode, std::vector<heapnode>, mycomparator> hp1; //line1 std::priority_queue<heapnode, mycomparator> hp2; //line2 }
tried 2 ways shown on line1 , line2. neither line can pass compilation.
std::priority_queue takes 3 arguments in constructor:
template< class t, class container = std::vector<t>, class compare = std::less<typename container::value_type> > class priority_queue;
in case line1 looks fine , should compile. error message?
in line2 trying create std::priority_queue of custom type (heapnode) container "mycomparator" (not container!).
the type of underlying container use store elements. container must satisfy requirements of sequencecontainer. additionally, must provide following functions usual semantics: front(), push_back(), pop_back(). standard containers std::vector , std::deque satisfy these requirements.
http://en.cppreference.com/w/cpp/container/priority_queue
"mycomparator" not container , doesn't support required methods.
i checked code line2 commented out , compiles. have included , ? have main function somewhere?
Comments
Post a Comment