A virtual destructor in C++, when? -- Andreas Fertig
When should a destructor be virtual in C++? In this post, we’ll explore a real-world example from smart pointer implementation to illustrate when virtual destructors are necessary — and when they’re not.
A virtual destructor in C++, when?
by Andreas Fertig
From the article:
In today's post, I would like to explain a design rationale used in my post Understanding the inner workings of C++ smart pointers - The shared_ptr.
Keen readers spotted that in my implementation of
ctrl_blk_base, I didn't make the destructorvirtual. Here is the original code for easy reference:![]()

C++26 is bringing a long-awaited feature to the language: compile-time reflection, enabling programs to introspect and manipulate their own structure during compilation. This powerful capability opens the door to eliminating boilerplate, improving performance, and writing more expressive, reusable code with ease.