[#bsl-shared_ptr-0a-2constructor-0dd]
= xref:bsl.adoc[bsl]::xref:bsl/shared_ptr-0a.adoc[shared&lowbar;ptr]::shared&lowbar;ptr
:relfileprefix: ../../
:mrdocs:

Create a shared pointer that manages a modifiable object of (template parameter) type `CONVERTIBLE&lowbar;TYPE`, refers to the specified `ptr` cast to a pointer to the (template parameter) type `ELEMENT&lowbar;TYPE`, and uses the specified `deleter` to delete the shared object when all references have been released&period; Use the specified `basicAllocator` to allocate and deallocate the internal representation of the shared pointer (including a copy of the `deleter`)&period; The (template parameter) type `DELETER` shall be either a function pointer or a function&hyphen;like deleter that may be invoked to destroy the object referred to by a single argument of type `CONVERTIBLE&lowbar;TYPE &ast;` (i&period;e&period;, `deleter(ptr)` will be called to destroy the shared object)&period; (See the &quot;Deleters&quot; section in the component&hyphen; level documentation&period;) The (template parameter) type `ALLOCATOR` shall satisfy the Allocator requirements of the C&plus;&plus; standard (C&plus;&plus;11 17&period;6&period;3&period;5, &lsqb;allocator&period;requirements&rsqb;)&period; If `CONVERTIBLE&lowbar;TYPE &ast;` is not implicitly convertible to `ELEMENT&lowbar;TYPE &ast;`, then a compiler diagnostic will be emitted indicating the error&period; If `ptr` is 0, then the null pointer will be reference counted, and `deleter(ptr)` will be called when the last reference is destroyed&period; If an exception is thrown when allocating storage for the internal representation, then `deleter(ptr)` will be called&period; The behavior is undefined unless the constructor making a copy of `deleter` does not throw an exception&period; Note that the final dummy parameter is a simple SFINAE check that the (template parameter) `ALLOCATOR` type probably satisfies the standard allocator requirements&semi; in particular, it will not match pointer types, so any pointers to `bslma&colon;&colon;Allocator` derived classes will dispatch to the constructor above this, and not be greedily matched to a generic type parameter&period;

== Synopsis

Declared in `&lt;bslstl&lowbar;sharedptr&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class CONVERTIBLE&lowbar;TYPE,
    class DELETER,
    class ALLOCATOR&gt;
shared&lowbar;ptr(
    CONVERTIBLE&lowbar;TYPE* ptr,
    DELETER deleter,
    ALLOCATOR basicAllocator,
    ALLOCATOR::value&lowbar;type* = 0);
----


[.small]#Created with https://www.mrdocs.com[MrDocs]#
