[#bsl-enable_shared_from_this] = xref:bsl.adoc[bsl]::enable_shared_from_this :relfileprefix: ../ :mrdocs: 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`. == Synopsis Declared in `<bslstl_sharedptr.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class ELEMENT_TYPE> class enable_shared_from_this; ---- == Description 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]# | Constructors | 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`] | Provides the implementation of a signaler. This object has a 1‐1 relationship with the `Signaler`, which has a shared pointer to it. This allows other objects to refer to it via shared and weak pointers. This allows `SignalerConnection` objects to outlive the `Signaler ‐ Signaler_Node` pair, since they can test or lock weak pointers to see if the `Signaler_Node` still exists when they are trying to disconnect themselves. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#