Channels ▼   Destructors Considered Harmful  Staying Out of
Harm's Way  The key to avoiding destructors is to realize that a
destructor is always executed in addition to the destructors of
its class' data members and base classes. Therefore, although it
is not possible to avoid destructors completely, it is possible
to encapsulate them in classes that do nothing but allocate and
free resources. One such class is the shared_ptr template from
the new C++ standard. Using it, we can rewrite our ThingHandle
class this way:  // This version avoids the hazard class
ThingHandle {      ThingHandle(): tp(new Thing) { }      // …
std::shared_ptr<Thing> tp;  By changing the type of our tp
member from Thing* to std::shared_ptr<Thing>, we have handed the
job of worrying about memory allocation to the shared_ptr class,
thereby dropping the destructor from ThingHandle entirely. If
the compiler generates a copy constructor or assignment operator
for us (or, in the new C++ standard, a move constructor or move-
assignment o