Quick Q: Why does ~shared_ptr amazingly know how to call the right destructor?—StackOvervflow

Save to:
Instapaper Pocket Readability

Quick A: Because shared_ptr is awesome and remembers the correct deleter to call.

Recently on SO:

Why does incomplete type of smart pointer data member and raw pointer data member have different behavior when their parent destruct?

In the following code:

smart pointer data member pImpl(class Impl) and raw pointer pc(class CAT) all are incomplete data type, there is no definition of these two classes in Widget.h ...

... For the raw pointer data member, its destuctor is not called when widget object is destructed.

While the shared_ptr data member, its destructor has been correctly called.

... Why do shared_ptr data member and raw data member have different behavior when the widget gets destructed?

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.