Virtual Destructors in C++

If multiple objects are created dynamically in the derived class, a dangerous situation occurs. More and more un-referenced memory blocks will clutter up the main memory without you being able to reallocate them—this can seriously impact your program’s response and even lead to external memory being swapped in. This issue can be solved simply by declaring virtual destructors. A class used as a base class for other classes should always have a virtual destructor defined. Even if the base class does not need a destructor itself, it should at least…

Read More