std::weak_ptr<T>::operator=
来自 cppreference.cn
weak_ptr& operator=( const weak_ptr& r ) noexcept; |
(1) | (自 C++11 起) |
template< class Y > weak_ptr& operator=( const weak_ptr<Y>& r ) noexcept; |
(2) | (自 C++11 起) |
template< class Y > weak_ptr& operator=( const shared_ptr<Y>& r ) noexcept; |
(3) | (自 C++11 起) |
weak_ptr& operator=( weak_ptr&& r ) noexcept; |
(4) | (自 C++11 起) |
template< class Y > weak_ptr& operator=( weak_ptr<Y>&& r ) noexcept; |
(5) | (自 C++11 起) |
将托管对象替换为 r 托管的对象。对象与 r 共享。如果 r 不托管任何对象,则 *this 也不托管任何对象。
1-3) 等价于 std::weak_ptr<T>(r).swap(*this)。
4,5) 等价于 std::weak_ptr<T>(std::move(r)).swap(*this)。
目录 |
[编辑] 参数
r | - | 智能指针,用于与另一个 weak_ptr 共享对象 |
[编辑] 返回值
*this
[编辑] 注解
实现可能在不创建临时的 weak_ptr
对象的情况下满足要求。
[编辑] 缺陷报告
以下行为变更缺陷报告被追溯应用于先前发布的 C++ 标准。
DR | 应用于 | 已发布行为 | 正确行为 |
---|---|---|---|
LWG 2315 | C++11 | 未为 weak_ptr 启用移动语义 |
已启用 |
[编辑] 参见
创建新的 weak_ptr (公共成员函数) | |
交换托管对象 (公共成员函数) |