When creating a std::unique_ptr in C++, one usually passes the extra delete functor as the template parameter. But std::shared_ptr needs it as the constructor parameter.

The answer1 explains that std::unique_ptr binds the deleter to its type to avoid the runtime overhead of an indirect call for the deleter. std::shared_ptr binds it at runtime to make it easier for users to override the deleter2.

templateclass Yclass Deleter >  
shared_ptr( Y* ptr, Deleter d );

Note by default, the default deleter is std::default_deleter<T>3 :

    class T,  
    class Deleter = std::default_delete<T>  
class unique_ptr;


  1. https://stackoverflow.com/a/70879616

  2. https://en.cppreference.com/w/cpp/memory/shared_ptr/shared_ptr

  3. https://en.cppreference.com/w/cpp/memory/unique_ptr