Export (0) Print
Expand All

enable_shared_from_this Class

Helps generate a shared_ptr.

template<class Ty>
    class enable_shared_from_this {
    shared_ptr<Ty> shared_from_this();
    shared_ptr<const Ty> shared_from_this() const;

    enable_shared_from_this(const enable_shared_from_this&);
    enable_shared_from_this& operator=(const enable_shared_from_this&);


The type controlled by the shared pointer.

The template class can be used as a public base class to simplify creating shared_ptr Class objects that own objects of the derived type:

class derived
    : public enable_shared_from_this<derived>

shared_ptr<derived> sp0(new derived);
shared_ptr<derived> sp1 = sp0->shared_from_this();

The constructors, destructor, and assignment operator are protected to help prevent accidental misuse. The template argument type Ty must be the type of the derived class.

Header: <memory>

Namespace: std

© 2014 Microsoft