[#bsl-enable_shared_from_this] = xref:bsl.adoc[bsl]::enable_shared_from_this :relfileprefix: ../ :mrdocs: Mixin enabling an object to obtain a `shared_ptr` to itself. == Synopsis Declared in `<bslstl_sharedptr.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class ELEMENT_TYPE> class enable_shared_from_this; ---- == Description This class allows an object that is currently managed by a `shared_ptr` to safely generate a copy of the managing `shared_ptr` object. Inheriting from `enable_shared_from_this<ELEMENT_TYPE>` provides the (template parameter) `ELEMENT_TYPE` type with a member function `shared_from_this`. If an object of type `ELEMENT_TYPE` is managed by a `shared_ptr` then calling `shared_from_this` will return a `shared_ptr<ELEMENT_TYPE>` that shares ownership of that object. It is undefined behavior to call `shared_from_this` on an object unless that object is managed by a `shared_ptr`. The intended use of `enable_shared_from_this` is that the (template parameter) type `ELEMENT_TYPE` inherits directly from the `enable_shared_from_this` class template. In the case of multiple inheritance, only one of the base classes should inherit from the `enable_shared_from_this` class template. If multiple base classes inherit from `enable_shared_from_this`, then there will be ambiguous calls to the `shared_from_this` function. == Member Functions [cols="1,4"] |=== | Name| Description | xref:bsl/enable_shared_from_this/shared_from_this-0a2.adoc[`shared_from_this`] | `shared_from_this` overloads | xref:bsl/enable_shared_from_this/weak_from_this-0e.adoc[`weak_from_this`] | `weak_from_this` overloads |=== == Protected Member Functions [cols="1,4"] |=== | Name| Description | xref:bsl/enable_shared_from_this/2constructor-0a.adoc[`enable_shared_from_this`] [.small]#[constructor]# | Create an `enable_shared_from_this` object that is not owned by any `shared_ptr` object. | xref:bsl/enable_shared_from_this/2destructor.adoc[`~enable_shared_from_this`] [.small]#[destructor]# | Destroy this `enable_shared_form_this`. | xref:bsl/enable_shared_from_this/operator_assign.adoc[`operator=`] | Return `*this`. This object is unchanged. Note that the specified `rhs` is not used. |=== == Derived Classes [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bdlmt/Signaler_Node.adoc[`Signaler_Node`] | Shared implementation object backing a `Signaler`. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#