A virtual destructor in C++, when? -- Andreas Fertig

2025-07-01-when-to-not-use-a-virtual-dtor-tw.pngWhen 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 destructor virtual. Here is the original code for easy reference:


Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.