I\'ve been mulling over use of unique_ptr
vs shared_ptr
vs own_solution
. I\'ve discounted the latter as I\'ll almost certainly get it
In the end, you cannot force anyone to listen. Ask at microsoft, apple or any open source library developer, they all know that song. A comment in the right words and places is your best bet.
Avoid creating your own smart pointer class, it hinders composition and reduces readability. As a last resort, try looking in boost, or any framework your code already has to work with.
If you have non-owners, they are either electable for holding weak_ptr
s or (if it is guaranteed to stay valid for the duration) raw pointers.
If you use shared_ptr
s internally (why should you), best provide weak_ptr
and raw pointers.
All those smart pointers explicitly denote an ownership policy. Raw pointers denote none or non-owning.
auto_ptr
: Do not use, deprecated with too many traps even for the wary.unique_ptr
: Sole ownership.shared_ptr
: Shared ownershipweak_ptr
: No ownership, might get deleted behind your back.