After searching around the web I did not manage to find an answer to this question:
I have this overloaded method:
foo(Base* base);
foo(Derived* derived);
In this case "Derived" is a subclass of "Base".
When I call:
foo(new Derived());
I notice that always the first overloaded method is called, while I would like to achieve the opposite result (call the method which takes a "Derived*" object as a parameter).
How to solve this? Thank you.
EDIT:
Ok, this is my actual situation:
I have an UIWidget and a UIScoreLabel class. UIScoreLabel derives from UIWidget. I also have a GameEvent class (Base) and a P1ScoreGameEvent class (Derived).
UIWidget:
virtual void handleGameEvent(GameEvent* e) { printf("ui_widget"); }
UIScoreLabel:
virtual void handleGameEvent(P1ScoreGameEvent* e) { printf("ui_score_label"); }
This is the call:
UIWidget* scoreLabel = new UIScoreLabel();
scoreLabel.handleGameEvent(new P1ScoreGameEvent());
Output:
ui_widget
I don't understand what I'm doing wrong.