In new smart_ptr<SString>(new SString("but lost")); you are creating a new dynamically assigned smart pointer. You do not save the distribution result (pointer to shared_ptr to SString ) anywhere, it hangs ... since you do not save the result, you also cannot call delete for it - therefore, the destructor will not be called, and in turn, the SString destructor the contained object will not be called!
If you try
smart_ptr<SString> *p = new smart_ptr<SString>(new SString("but lost")); delete p;
instead, you will see a destructor called also for this case.
However, that is a reasonable use of a smart_ptr . smart_ptr were created so that you do not need to call delete manually; therefore do not use them in this way; use them as in your first application!
source share