Recently on StackOverflow:
Why does unique_ptr take two template parameters when shared_ptr only takes one?
Both
unique_ptr
andshared_ptr
accept a custom destructor to call on the object they own. But in the case ofunique_ptr
, the destructor is passed as a template parameter of the class, wherease the type ofshared_ptr
's custom destructor is to be specified as a template parameter of the constructor.template <class T, class D = default_delete<T>> class unique_ptr { unique_ptr(T*, D&); //simplified ... };
and
template<class T> class shared_ptr { template<typename D> shared_ptr(T*, D); //simplified ... };
I can’t see why such difference. What requires that?
Add a Comment
Comments are closed.