I have a queue that contains Objects of class Event.
std::priority_queue<Event> events;
But Event is just a superclass of actual events. Lets assume we have following classes:
class Event{
public:
void Action(){
std::cout<<"do nothing"<<std::endl;
}
};
class XEvent : public Event{
public:
void Action(){
std::cout<<"do x"<<std::endl;
}
class YEvent : public Event{
public:
void Action(){
std::cout<<"do y"<<std::endl;
}
};
and in the main function:
int main(){
std::vector<Event> events;
events.push_back(XEvent x);
events.push_back(YEvent y);
Event e = events[0];
e.Action();
}
I want e.Action to behave according to overridden version. (i.e "do x").
But instead the output gives me "do nothing". Any suggestion?
p.s. Im actually looking for a way to do this without using pointers