跳到主要内容

std::enable_shared_from_this<T>::weak_from_this

自 C++17 起
std::weak_ptr<T> weak_from_this() noexcept;                 (1)
std::weak_ptr<T const> weak_from_this() const noexcept; (2)

返回一个 std::weak_ptr<T>,该指针跟踪对 *this 的所有现有 std::shared_ptr*this 的所有权。

备注

这是 enable_shared_from_this 私有的可变 weak_ptr 成员的副本。

返回值

std::weak_ptr<T>,与现有的 std::shared_ptr 共享对 *this 的所有权。

示例

本节不完整

std::enable_shared_from_this<T>::weak_from_this

自 C++17 起
std::weak_ptr<T> weak_from_this() noexcept;                 (1)
std::weak_ptr<T const> weak_from_this() const noexcept; (2)

返回一个 std::weak_ptr<T>,该指针跟踪对 *this 的所有现有 std::shared_ptr*this 的所有权。

备注

这是 enable_shared_from_this 私有的可变 weak_ptr 成员的副本。

返回值

std::weak_ptr<T>,与现有的 std::shared_ptr 共享对 *this 的所有权。

示例

本节不完整