I have some specific questions on virtual destructors and vtable.
Suppose I have the following code:
class Base
{
public:
virtual ~Base();
};
class Child : public Base
{
public:
~Child();
};
Questions:
- Where is the vtable stored? Is it always in the base class and all sub-classes simply keeps a pointer to it?
- Adding a virtual method only increases the sizeof(class) by 8 bytes right? (assume 64bit system) How about base class if it stores the table?
- Creating an instance of type Child via the new operator then delete ... will the Base destructor be called? (I'm asking because Child class's destructor isn't virtual ... does that mean it only affects sub-class of Child?).
Childto actually be a child-class ofBase? - Some programmer dudevirtualoroverrideor not; that's optional but does not change the fact that the derived dtor is virtual. - Jesper Juhl