NOTE: Last year, I posted three new GotWs numbered #103-105. I decided leaving a gap in the numbers wasn’t best after all, so I am renumbering them to #89-91 to continue the sequence. Here is the updated version of what was GotW #103.

There’s a lot to love about standard smart pointers in general, and unique_ptr in particular.



Problem



JG Question



1. When should you use shared_ptr vs. unique_ptr? List as many considerations as you can.

Guru Question



2. Why should you almost always use make_shared to create an object to be owned by shared_ptrs? Explain.

3. Why should you almost always use make_unique to create an object to be initially owned by a unique_ptr? Explain.

4. What’s the deal with auto_ptr?