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

Calling `std::shared_ptr<Bad>(this)` inside a member function, when the object is already managed by a `shared_ptr`, causes what problem?

struct Bad { std::shared_ptr<Bad> getPtr() { return std::shared_ptr<Bad>(this); } }; auto sp = std::make_shared<Bad>(); auto sp2 = sp->getPtr();