Item 44 in [[EffC++]] offers a summary that basically says
1) a pure virtual means
only interface is inherited (since parent provides no implementation)
2) a “simple/traditional virtual” means interface plus a default implementation is inherited
3) a non-virtual means interface plus a mandatory implementation is inherited and subclasses are advised to keep the implementation. C++ actually allows subclass to /deviate/ by redefining and hiding the parent implementation. Java has a cleaner solution in the “final” keyword.
I’d like to add
1b) a pure-virtual-with-an-implementation tells the subclass author
“Inherit this interface. By the way I also offer an implementation upon request, but uninheritable.”
This differs from (2). Both are illustrated in Item 36.
Author of a subclass of an abstract base class (featuring pure2()) can choose one of three options:
- 1. don’t declare pure2() at all. As the default and most popular usage, the subclass is also abstract (pun intended) by virtual of the inherited pure2().
- 2. define pure2(), and becoming a non-abstract class
- … so far, exactly same as java syntax
- 3. redeclare the same pure2() without implementation — an error. See P215 [[ARM]]