Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumC++shared_ptr and weak_ptrSingle-choice MCQ

This code aims to get a shared_ptr to 'this' from inside a member. What is wrong, and what fixes it?

struct Node { std::shared_ptr<Node> self() { return std::shared_ptr<Node>(this); } }; auto n = std::make_shared<Node>(); auto s = n->self();