Advertisement Jump to content
  • Advertisement
Sign in to follow this  
  • entry
  • comments
  • views

About this blog

A jourmal on my encounters with programming knols.

Entries in this blog


Virtual ~Destructor(){}

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.



Sign in to follow this  
  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!