L
lallous
Hello
I have a design / C++ question, hope you can help me.
class interface1
{
protected:
int _priority;
public:
virtual ~interface1() { };
interface1(int priority) { _priority = priority; }
virtual void on_event() { }
};
Now users can subclass this interface and override the on_event().
Now I have an std::list<interface *>
However, the std::list does not sort the elements.
Thus I want to use an std::set<> instead that will sort the "interface1 *",
providing it with a comparison function that will sort according to
priority, so that later I can iterate in a sorted manner.
I would have used priority_queue, however I want to be able to register and
unregister arbitrary interfaces.
std::set allows one to remove and insert anywhere.
Please advise.
I have a design / C++ question, hope you can help me.
class interface1
{
protected:
int _priority;
public:
virtual ~interface1() { };
interface1(int priority) { _priority = priority; }
virtual void on_event() { }
};
Now users can subclass this interface and override the on_event().
Now I have an std::list<interface *>
However, the std::list does not sort the elements.
Thus I want to use an std::set<> instead that will sort the "interface1 *",
providing it with a comparison function that will sort according to
priority, so that later I can iterate in a sorted manner.
I would have used priority_queue, however I want to be able to register and
unregister arbitrary interfaces.
std::set allows one to remove and insert anywhere.
Please advise.