Override and final

As mentioned earlier, if you type the prototype of a derived virtual method wrong, for example, use the wrong parameter types, the compiler will treat the method as a new method and will compile it. It is perfectly legal for a derived class not to override the method of the base class; this is a feature that you will often want to use. However, if you make a mistake in typing the prototype of a derived virtual method, the base method will be called when you intended your new version to be called. The override specifier is designed to prevent this bug. When the compiler sees this specifier, it knows that you intend to override a virtual method inherited from a base class and it will search the inheritance chain to find a ...

Get Beginning C++ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.