Jezck wrote: |
---|
Hi, I have a query with regards to the use of the Virtual keyword for methods. If a derived class overrides a virtual method of a base class, and the Virtual keyword is also used i the .h of the derived class Then it seems to call the overridden method of the derived class even if The object type is of the base class. I’m not sure how that is possible but does happen. Now if I remove the virtual keyword from the .h of the derived class then the base class method is called instead of the object calling the method is of the base class type. I did not think there should be any behaviour difference if the virtual keyword was used or not used in the .h of the derived class. |
|
|
Thanks, that is what I see also. Except in the case where the parameter of the method takes in the base class type and the object being passed to it is of the derived type then within that method I can see the derived method is called but only if virtual is used for the derived method which overrides the base class method. If I remove the virtual keyword then the base class method is called so the behaviour is different in this case. |