August 15, 2025Aug 15 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 destructor virtual. Here is the original code for easy reference: View the full article
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.