KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
My priority queue declared as: std::priority_queue<*MyClass> queue; class MyClass { bool operator<( const MyClass* m ) const; } is not sorting the items in the queue. What is wrong? I would not like to implement a different (Compare) class. Answer summary: The problem is, the pointer addresses are sorted. The only way to avoid this is a class that 'compares the pointers'. Now implemented as: std::priority_queue<*MyClass, vector<*MyClass>, MyClass::CompStr > queue; class MyClass { struct CompStr { bool operator()(MyClass* m1, MyClass* m2); } }
Tags (comma-separated)
Save Edits
Cancel