Seems like maybe shared pointers could be useful across threads when both pointers are accessing same object.
But otherwise I can't think of a single time when I would need a shared pointer and a unique pointer wouldn't do the trick. Can you?
Seems like maybe shared pointers could be useful across threads when both pointers are accessing same object.
But otherwise I can't think of a single time when I would need a shared pointer and a unique pointer wouldn't do the trick. Can you?
What are situations when a shared smart pointer is needed and unique can't be used?
Every time you need shared ownership.
It should not be a common occurrence, but there are some cases that stand out, like graph-like structures (including cycles), some async programming patterns, long-lived objects with no clear owner and the desire to avoid globals, etc.