std::enable_shared_from_this<T>::enable_shared_from_this
提供: cppreference.com
<tbody>
</tbody>
constexpr enable_shared_from_this() noexcept; |
(1) | (C++11以上) |
enable_shared_from_this( const enable_shared_from_this<T>&obj ) noexcept; |
(2) | (C++11以上) |
新しい enable_shared_from_this オブジェクトを構築します。 プライベートな std::weak_ptr<T> メンバは値初期化されます。
引数
| obj | - | コピーする enable_shared_from_this
|
ノート
ムーブコンストラクタはありません。 shared_from_this から派生したオブジェクトからのムーブは、その共有されている同一性を転送しません。
例
Run this code
#include <memory>
struct Foo : public std::enable_shared_from_this<Foo> {
Foo() {} // implicitly calls enable_shared_from_this constructor
std::shared_ptr<Foo> getFoo() { return shared_from_this(); }
};
int main() {
std::shared_ptr<Foo> pf1(new Foo);
auto pf2 = pf1->getFoo(); // shares ownership of object with pf1
}
関連項目
(C++11) |
共有オブジェクト所有権のセマンティクスを持つスマートポインタ (クラステンプレート) |