I have a template class that contains a std:
riority_queue and would like for the user of this class to be able to pass in the functor object that is used for comparison. Here is the code I have but it is not working. I kind of didn't think it would be thought I would give it a try. Maybe I am going about this the wrong way.
Code:
template <typename T>
class ProcessingQueue {
public:
class Comparer
{
public:
virtual bool operator()(T* obj1, T* obj2) {
return true;
}
};
.
.
.
void push(T* element);
virtual void processElement(T* element) = 0;
.
.
.
private:
std::priority_queue<T*, std::vector<T*>, Comparer> m_vector;
.
.
.
}
This class creates and manages a thread that takes elements that are put on the queue and processes them. I had this working fine using a vector but want to convert it to a priority_queue to allow elements to be processed based on a user defined priority.
My initial thought was to create the Comparer class to provide as the thrid template parameter to priority_queue and let users derive a specific Comparer for there type implementing an appropriate operator() overload. This did not work and after digging into it a little more I understand why.
Am I going about this the wrong way?
Can someone help with how to go about this?
Please let me know if more information is needed. I tried to only post relevant code.
Thanks.