Re:Mistakes to avoid with C++ 11 smart pointers
by hellofunk on Sunday May 15, 2016 @03:52AM
(#11699960)
>instead of having clear memory ownership contracts
You have a good point for shared_ptr, but unique_ptr offers the best clarity for ownership, much better than raw pointers, since owning and non-owning pointers all look the same, but a unique_ptr that hands out regular pointers to its memory makes it clear in the code who owns what.
Use smart ptrs (especially shared_ptrs) instead of having clear memory ownership contracts and incorporating memory ownership into your design. Two objects each having a shared_ptr to the same object as a member should raise red flags.