Putting destructors aside, the implementation of pure virtual functions is a strange thing, because they are never called in a natural way. that is, if you have a pointer or reference to your base class, the base object will always be some Derived, which overrides the function and will always be called.
The only way to get the calling implementation is to use the Base :: func () syntax from one of the overloaded derived classes.
This actually, in some way, makes it the best target for embedding, since the moment the compiler wants to call it, it is always clear which overload is being called.
In addition, if implementations for pure virtual functions were forbidden, there would be an obvious workaround for some other (possibly protected) non-virtual function in the Base class, which you could just call in the usual way from your derived function. Of course, the volume will be less limited, since you could call it any function.
(By the way, I believe that Base::f() can only be called with this syntax from Derived::f() , and not from Derived::anyOtherFunc() . Am I correct with this assumption?).
Pure virtual destructors are a completely different story, in a way. It is used as a method simply so that someone does not instantiate the derived class without having any pure virtual functions elsewhere.
The answer to the actual question βwhyβ is not resolved, in fact simply because the standards committee said so, but my answer sheds some light on what we are trying to achieve anyway.
CashCow Jan 03 '13 at 12:12 2013-01-03 12:12
source share