What is the purpose of a Virtual Destructor?

Last updated 5 July 2026

  • In C++, a virtual destructor ensures deleting a derived object through a base pointer runs the derived destructor first, then the base.

  • Without it, delete on a Base* runs only the base destructor, causing undefined behavior and leaks.

  • Give every polymorphic base class one. The cost is a vtable pointer per object, so skip it for classes never used polymorphically.

  • https://www.reddit.com/r/developersIndia/comments/1ktgmfk/software_development_interview_preparation/
  • https://www.reddit.com/r/programming/comments/1m2ff3j/casey_muratori_the_big_oops_anatomy_of_a/
  • https://www.reddit.com/r/SoftwareEngineering/comments/1ijqgpb/is_the_o_in_solid_still_relevant_or_just_a_relic/
  • https://www.reddit.com/r/NorthropGrumman/comments/1bt1ug3/monthly_employmentcorporate_questions_and/
All Object-Oriented Programming interview questions