Why do we need a virtual destructor in a base class? What happens if you delete a derived class object through a base class pointer without one?

Last updated 21 June 2026

  • Deleting a derived object through a base pointer without a virtual destructor is undefined behavior. Typically only ~Base() runs, leaking derived resources.

  • A virtual destructor dispatches through the vtable, so the dynamic type's destructor runs first, then the bases in reverse order.

  • Give every polymorphic base a virtual destructor. Skip it for non-polymorphic classes to avoid needless vptr overhead.

  • https://utkrusht.ai/blog/cplusplus-interview-questions
  • https://roadmap.sh/questions/cpp
  • https://internshala.com/blog/cpp-coding-interview-questions/
All C++ interview questions