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;
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 due to overriding and hiding the function, but still do not understand the behavior in this code.
user152508
source share