c++ - How to destroy a smart pointer prematurely -
i have class has setter method takes unique_ptr argument. unique_ptr saved class member.
class testclass { std::unique_ptr<tester> sp; void settester_way1(std::unique_ptr<tester> te) { auto deleter=std::move(sp); sp=std::move(te); } void settester_way2(std::unique_ptr<tester> te) { sp=std::move(te); } };
which way correct way set smart pointer? way2 leak original pointer of sp?
way2 fine, when assign unique_ptr
existing owned pointer safely deleted.
Comments
Post a Comment