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)
|
умный указатель с семантикой совместного владения объектом
(шаблон класса) |