I have this code :
class Event{};
class CustomEvent:public Event{};
class Handler
{
public:
virtual void inform(Event e ){}
};
class CustomHandler : public Handler
{
public:
void inform(CustomEvent e){}
};
CustomEvent cEvent;
Handler* handler = new CustomHandler;
//this calls Handler::inform(Event), not CustomHandler::(CustomEvent) , as I expected
handler->inform(cEvent);
If I change the code to this :
class Handler
{
public:
virtual void inform(Event e ){}
virtual void inform(CustomEvent e){}
};
class CustomHandler : public Handler
{
public:
void inform(CustomEvent e){}
};
CustomEvent cEvent;
Handler* handler = new CustomHandler;
//this calls CustomHandler::(CustomEvent)
handler->inform(cEvent);
I read that this is connected with function overriding and hiding but still doesn't understand the behavior in this code.