Question 20
Back to Exercise
How do you turn a unique_ptr into a shared_ptr?
- A It is impossible
- B Move it: std::shared_ptr<T> s = std::move(u); Correct
- C Copy it: s = u;
- D Call u.share()
Correct Answer: Option B
That is why factories return unique_ptr: callers can choose either kind of ownership.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!