std::enable_shared_from_this<T>:: enable_shared_from_this
From cppreference.net
<
cpp
|
memory
|
enable shared from this
C++
Memory management library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::enable_shared_from_this
| Protected member functions | ||||
|
enable_shared_from_this::enable_shared_from_this
|
||||
| Public member functions | ||||
|
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)
|
共有オブジェクト所有権セマンティクスを持つスマートポインタ
(クラステンプレート) |