Which smart pointer is designed for non-owning observation of an object managed by shared_ptr?
Options
- A. unique_ptr
- B. shared_ptr
- C. weak_ptr
- D. More than one of the above
- E. None of the above
Quiz Practice:
C. weak_ptr
Answer: weak_ptr
std::weak_ptr provides a non-owning reference to an object managed by std::shared_ptr.
Unlike shared_ptr, a weak_ptr does not increase the strong reference count.
It is especially useful for avoiding ownership cycles between objects managed by shared_ptr.