Namespaces
Variants

std::enable_shared_from_this<T>:: enable_shared_from_this

From cppreference.net
Memory management library
( exposition only* )
Allocators
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Memory resources
Uninitialized storage (until C++20)
( until C++20* )
( until C++20* )
( until C++20* )

Garbage collector support (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
constexpr enable_shared_from_this ( ) noexcept ;
(1) (C++11以降)
enable_shared_from_this ( const enable_shared_from_this & other ) noexcept ;
(2) (C++11以降)

enable_shared_from_this オブジェクトを新しく構築します。 weak_this 値初期化 されます。

目次

パラメータ

その他 - enable_shared_from_this のコピー対象

注記

ムーブコンストラクタは存在しません: enable_shared_from_this から派生したオブジェクトからのムーブは、その共有されたアイデンティティを転送しません。

#include <memory>
struct Foo : public std::enable_shared_from_this<Foo>
{
    Foo() {} // enable_shared_from_thisのコンストラクタを暗黙的に呼び出す
    std::shared_ptr<Foo> getFoo() { return shared_from_this(); }
};
int main()
{
    std::shared_ptr<Foo> pf1(new Foo);
    auto pf2 = pf1->getFoo(); // pf1とオブジェクトの所有権を共有する
}

関連項目

(C++11)
共有オブジェクト所有権セマンティクスを持つスマートポインタ
(クラステンプレート)