In C++ why the pure virtual
method mandates its compulsory overriding only to its immediate children (for object creation), but not to
In your example, you have not declared D::foo
pure; that is why it does not need to be overridden. If you want to require that it be overridden again, then declare it pure.
If you want to be able to instantiate D
, but force any further derived classes to override foo
, then you can't. However, you could derive yet another class from D
that redeclares it pure, and then classes derived from that must override it again.