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

What is wrong with passing this lambda as a custom deleter to a `std::unique_ptr`, compared with using it for a `std::shared_ptr`?

auto del = [](FILE* f){ if (f) fclose(f); }; std::unique_ptr<FILE> up(fopen("x","r")); // line 1 std::shared_ptr<FILE> sp(fopen("x","r"), del); // line 2