Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumC++unique_ptrSingle-choice MCQ

What is the danger in this code that converts a derived `unique_ptr` to a base `unique_ptr`?

struct Base { ~Base() {} }; // non-virtual struct Derived : Base { std::string big; }; std::unique_ptr<Base> b = std::make_unique<Derived>(); // b goes out of scope here