3 ms·
Herb Sutter gave a really great talk on this: https://www.youtube.com/watch?v=JfmTagWcqoE https://www.youtube.com/watch?v=JfmTagWcqoE He has 3 guidelines: 1.
by shermanyo 10y ago
Herb Sutter gave a really great talk on this:
https://www.youtube.com/watch?v=JfmTagWcqoE https://www.youtube.com/watch?v=JfmTagWcqoE
He has 3 guidelines:
1. Prefer scoped lifetimes by default (local members)
2. Else prefer unique_ptr and containers
3. Else consider shared_ptr
His whole talk gives examples that show the flexibility of unique_ptr and how modern C++ can express ownership.
See slide 5 here:
https://github.com/CppCon/CppCon2016/blob/master/Presentations/Lifetime%20Safety%20By%20Default%20-%20Making%20Code%20Leak-Free%20by%20Construction/Lifetime%20Safety%20By%20Default%20-%20Making%20Code%20Leak-Free%20by%20Construction%20-%20Herb%20Sutter%20-%20CppCon%202016.pdf https://github.com/CppCon/CppCon2016/blob/master/Presentatio...