J
Juha Nieminen
Pallav said:Hi All
How Does compiler implement virtual destructor ???
as we all know if base class destructor is virtual..........then while
wriiting statemnt like this
Base * b = new Derived( );
delete b;
// it will call Deived class destructor Followed by Base Class
How compiler does House-keeping for it in V-Table ??
It's most probably again one thing which the standard doesn't specify,
but which all compilers do in the same way:
If there exists any virtual functions in a class (eg. a virtual
destructor) the size of the class will be increased by a pointer.
Internally this pointer points to a virtual table which contains
pointers to the virtual functions at fixed offsets. When calling a
virtual function (eg. the destructor), what it actually does is that it
takes that pointer, indexes it with a fixed value, takes the function
pointer found there and calls that function. If it's a destructor, then
the destructor will call the destructor of its own base class, etc.