3 ms·
A concrete object must implement all virtual methods including those marked as pure virtual. All =0 means is that someone else lower down the inheretence chain
by jdsully 5y ago
A concrete object must implement all virtual methods including those marked as pure virtual. All =0 means is that someone else lower down the inheretence chain will implement this and the caller using the class type can rely on it existing.
If you try to instantiate an object without all methods implemented you'll get a compiler error about the class being "abstract". You should never have a case where there's a null in the vtable.
If there is some specific edge case around ctors then forgive me - this is C++ after all! But in practice you don't have to worry about this which is true for most of the C++ minutia.
- cesarb 5y ago> If there is some specific edge case around ctors then forgive me - this is C++ after all! Yes, the specific edge case is around ctors and dtors. During the ctor or the dtor, the vtable is the vtable of the base class, not the derived class, so if you call a virtual function within the ctor or dtor of the base class (don't do that), the function which will be called is the one from the (possibly abstract) base class. See for instance this FAQ entry: https://isocpp.org/wiki/faq/strange-inheritance#calling-virtuals-from-ctors https://isocpp.org/wiki/faq/strange-inheritance#calling-virt...