I just read many people writing "an online table is available for any class which has a virtual function declared inside itInch.
My real question is, does a vtable is available just for a category which has a virtual function or will it also exists for classes based on that class.
class Base class Derived:public Base //From primary.cpp Base* b = new Derived b->print()
Question: Had there been no vtable for class derived then your output will not have been "derived print". So IMO there is available a vtable for just about any class which has virtual function declared and in classes getting from that class. Is correct ?
So far as only virtual-function-specific functionality is recognized as, inside a traditional method of vtable implementation derived class would just have another version of vtable in the event that derived class overrides a minumum of one virtual function. Inside your example,
Derived overrides virtual function
Derived has it own version of
Derived vtable differs from that in
Base vtable. This could normally necessitate another vtable for
Derived did not override anything whatsoever, formally still it will be a separate polymorphic class, but to be able to make its virtual functions work correctly we're able to have simply used again
Base vtable for
Derived too. So, technically there would not be any requirement for another vtable for
However, in practical implementations, the information structure that people usually make reference to as "vtable", frequently holds some additional class-specific information too. That extra details are so class-specific that more often than not it might be impossible to talk about vtables between different classes in hierarchy, even when they will use exactly the same group of virtual functions. For instance, some implementations the vtable pointer saved in each polymorphic object indicates data structure which stores so known as "RTTI information" concerning the class. Because of this, in many (if not completely) practical implementations each polymorphic class will get its very own vtable, even when the virtual function pointers saved in individuals tables happen function as the same.
Yes, that's true. A category gets all data people from the base class, such as the vtable. However, vtable records are modified accordingly (for instance when the class overrides basics class virtual method, the related entry within the vtable must indicate its very own implementation).
But bear in mind that the idea of a 'vtable' is typical practice utilized by vitually every compiler, but it's not compulsory nor standardized.
Yes, knowing about it is correct. Any class which has a base with any virtual functions includes a vtable.
You heard that right. Really, given base's defintion:
class derived:public base
is totally equal to:
class derived:public base
... since you already defined print as virtual in base.
I'd wish the compiler would enforce that...
Find Out More About the Vtable @ below Link: http://world wide web.learncpp.com/cpp-tutorial/125-the-virtual-table/