Why it is needed to declare a template parameter for unique pointer while in shared pointer it isn't?
For a shared pointer we can just give a lambda
std::shared_ptr<Foo> sp std::shared_ptr<Foo>(new Foo, [](Foo* p){delete p;});
But for unique pointer we need the declaration to have a template parameter for the deleter
std::unique_ptr<Foo, void (*)(Foo*)> up = std::unique_ptr<Foo, void (*)(Foo*)>(new Foo, [](Foo* p){delete p;});
Aucun commentaire:
Enregistrer un commentaire