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

Inside a member function you need to hand out a shared_ptr to *this*, where the object is already managed by an existing shared_ptr. What is the correct mechanism, and what happens if you just write `return std::shared_ptr<T>(this);`?

struct Widget : std::enable_shared_from_this<Widget> { std::shared_ptr<Widget> getPtr() { /* ??? */ } };