I have a base class which I want to provide some \'base\' functionality for methods for all inheriting classes.
In my inheriting classes I want to do:
It says so because you have not declared the base method virtual
. Once you do so, the base virtual
/derived override
pair of keywords will make sense. Right now, the compiler is complaining that you cannot override
a non-virtual
method.
When you use the override keyword the derived method is used even when the instance is passed as a Base class type. Hence there needs to be a virtual in the base class so that the programme knows it has to make a runtime check of what the actual type of the instance is. It then looks up what the actual type is and if it is a derived type it checks if their is an override in the derived class for that particular method in the base class.
Member hiding is different. The base member will only be hidden if it is actually passed as an instance of the derived class. If the object is passed as a base class, the base class method will still be used. If you hide a member, you get a warning if you haven't use the new keyword. The new keyword is merely to tell the complier, that you really do mean to hide the base type method.