std::weak_ptr<T>::operator=
來自 cppreference.com
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 | - | 共享物件的智慧指標 |
[編輯] 返回值
*this
[編輯] 注意
實現可以不建立臨時的 weak_ptr
物件來滿足要求。
[編輯] 缺陷報告
下列更改行為的缺陷報告追溯地應用於以前出版的 C++ 標準。
缺陷報告 | 應用於 | 釋出時的行為 | 正確的行為 |
---|---|---|---|
LWG 2315 | C++11 | 未為 weak_ptr 啟用移動語義 |
已啟用 |
[編輯] 參見
建立新的 weak_ptr (public member function) | |
交換管理物件 (public member function) |