Abstract classes

A class with virtual methods is still a concrete class--you can create instances of the class. You may decide that you want to provide just a part of the functionality, with the intention that a user has to derive from the class and add the missing functionality.

One way to do this is to provide a virtual method that has no code. This means that you can call the virtual method in your class, and at runtime, the version of the method in the derived class will be called. However, although this provides a mechanism for you to call derived methods in your code, it does not force the implementation of those virtual methods. Instead, the derived class will inherit the empty virtual methods and if it does not override them, the ...

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.