다음을 통해 공유


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