About this blog
A jourmal on my encounters with programming knols.
Entries in this blog
I came across the keyword virtual placed next to a destructor in a CPP Ogre code written by my professor. Why and when do we use a virtual destructor ?
We use virtual destructors when somewhere in our code a pointer of a base class points to a derived class. When somewhere later in our code we try to delete this pointer, the destructor that gets called is the base class destructor and not the derived class destructor, which is not what we want since the pointer points to a derived class. This can result in a memory leak. To call the derived class destructor as well, we should make the base class destructor virtual.