enable_shared_from_this Class

帮助生成 shared_ptr。

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

protected:
    enable_shared_from_this();
    enable_shared_from_this(const enable_shared_from_this&);
    enable_shared_from_this& operator=(const enable_shared_from_this&);
    ~enable_shared_from_this();
    };

参数

  • Ty
    共享指针控件的类型。

备注

模板选件类可用于为公共基类简化创建该 shared_ptr Class 的对象由派生类型自己的对象:

class derived
    : public enable_shared_from_this<derived>
    {
    };

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

构造函数、析构函数和赋值运算符保护帮助防止无意滥用。模板参数类型 Ty 必须是派生类的类型。

要求

标头: <memory>

命名空间: std

请参见

参考

enable_shared_from_this::shared_from_this

shared_ptr Class