How to implement sorting method for a c++ priority_queue with pointers

前端 未结 4 1626
耶瑟儿~
耶瑟儿~ 2021-01-12 00:23

My priority queue declared as:

std::priority_queue<*MyClass> queue;

class MyClass {
    bool operator<( const MyClass* m ) const;
}
4条回答
  •  有刺的猬
    2021-01-12 00:56

    The operator <() you have provided will compare a MyClass object with a pointer to a MyClass object. But your queue contains only pointers (I think). You need a comparison function that takes two pointers as parameters.

    All this is based on some suppositions - please post your actual code, using copy and paste.

提交回复
热议问题