[#BloombergLP-bslma-ManagedPtr-0fa-2constructor-07]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslma.adoc[bslma]::xref:BloombergLP/bslma/ManagedPtr-0fa.adoc[ManagedPtr]::ManagedPtr
:relfileprefix: ../../../
:mrdocs:

Create a managed pointer having a target object referenced by the specified `ptr`, owning the managed object `&ast;ptr`, and having a deleter that will call `factory&hyphen;&gt;deleteObject(ptr)` to destroy the managed object when invoked (e&period;g&period;, when this managed pointer object is destroyed), unless `0 &equals;&equals; ptr`, in which case create an empty managed pointer&period; The deleter will invoke the destructor of `MANAGED&lowbar;TYPE` rather than the destructor of `TARGET&lowbar;TYPE`&period; This constructor will not compile unless `MANAGED&lowbar;TYPE &ast;` is convertible to `TARGET&lowbar;TYPE &ast;`&period; The behavior is undefined unless the managed object (if any) can be destroyed by the specified `factory`, or if `0 &equals;&equals; factory &amp;&amp; 0 !&equals; ptr`, or if the lifetime of the managed object is already managed by another object&period; Note that `bslma&colon;&colon;Allocator`, and any class publicly and unambiguously derived from `bslma&colon;&colon;Allocator`, meets the requirements for `FACTORY&lowbar;TYPE`&period;

== Synopsis

Declared in `&lt;bslma&lowbar;managedptr&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class MANAGED&lowbar;TYPE,
    class FACTORY&lowbar;TYPE&gt;
ManagedPtr(
    MANAGED&lowbar;TYPE* ptr,
    FACTORY&lowbar;TYPE* factory);
----


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