Thursday, February 4, 2010

Virtual Constructors and Virtual Destructors in C++

A constructor cannot be virtual because at the time when the constructor is invoked the virtual table would not be available in the memory. Hence we cannot have a virtual constructor.

A virtual destructor is one that is declared as virtual in the base class and is used to ensure that destructors are called in the proper order. It is to be remembered that destructors are called in the reverse order of inheritance. If a base class pointer points to a derived class object and we some time later use the delete operator to delete the object, then the derived class destructor is not called

1 comment:

  1. very informative post indeed .being enrolled in
    i was looking for such articles online to assist me and your article helped me a lot. i really like that you are providing such information.