Exception Safety with shared_ptr

Code snippet:

Output:

Exception safety is ensured, when using shared_ptr. Memory allocated by m_a is freed even when an exception is thrown. The trick is: the destructor of class shared_ptr is invoked after the destructor of class C.

Leave a Reply

Your email address will not be published. Required fields are marked *