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

Create a `shared&lowbar;ptr` managing `ptr` with a deleter and allocator&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&gt;
shared&lowbar;ptr(
    CONVERTIBLE&lowbar;TYPE* ptr,
    DELETER deleter,
    xref:BloombergLP/bslma/Allocator.adoc[BloombergLP::bslma::Allocator]* basicAllocator = 0);
----

== Description

Create a shared pointer that manages a modifiable object of (template parameter) type `CONVERTIBLE&lowbar;TYPE`, refers to the specified `(ELEMENT&lowbar;TYPE &ast;)ptr`, and uses the specified `deleter` to delete the shared object when all references have been released&period; Optionally specify a `basicAllocator` to allocate and deallocate the internal representation of the shared pointer (including a copy of `deleter`)&period; If `basicAllocator` is 0, the currently installed default allocator is used&period; `DELETER` shall be either a function pointer or a &quot;factory&quot; 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)` or `deleter&hyphen;&gt;deleteObject(ptr)` will be called to destroy the shared object)&period; (See the &quot;Deleters&quot; section in the component&hyphen;level documentation&period;) If `CONVERTIBLE&lowbar;TYPE &ast;` is not implicitly convertible to `ELEMENT&lowbar;TYPE &ast;`, then this constructor will not be selected by overload resolution&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;

== Parameters

[cols="1,4"]
|===
| Name| Description
| *ptr*
| pointer to the object to manage or refer to
| *deleter*
| deleter invoked when the last shared reference is released
| *basicAllocator*
| allocator used to supply memory
|===


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