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:![]()