In C++ why the pure virtual
method mandates its compulsory overriding only to its immediate children (for object creation), but not to the grand children and so on ?
struct B {
virtual void foo () = 0;
};
struct D : B {
virtual void foo () { ... };
};
struct DD : D {
// ok! ... if 'B::foo' is not overridden; it will use 'D::foo' implicitly
};
I don't see any big deal in leaving this feature out.
For example, at language design point of view, it could have been possible that, struct DD
is allowed to use D::foo
only if it has some explicit statement like using D::foo;
. Otherwise it has to override foo
compulsory.
Is there any practical way of having this effect in C++?
foo
bit out into a separate class and demand that every class inherit directly from that one (privately). – EdificeD
needs to overrideB::foo()
to be able to create an object of typeD
, however the same is not true forDD
.DD
object can still be instantiated, even though it doesn't overridefoo()
(implicitly it usesD::foo()
). My question is why is that ? – Maraud