std::auto_ptr<T>::operator auto_ptr<Y>
來自 cppreference.com
template< class Y > operator auto_ptr_ref<Y>() throw(); |
(1) | (C++11 中已棄用) (在 C++17 中已移除) |
template< class Y > operator auto_ptr<Y>() throw(); |
(2) | (C++11 中已棄用) (在 C++17 中已移除) |
將 *this 轉換為不同型別 Y
的 auto_ptr
。
[編輯] 引數
(無)
[編輯] 返回值
1) 一個持有 *this 引用的實現定義型別。
[編輯] 注意
提供來自 auto_ptr_ref
的建構函式和複製賦值運算子是為了允許從無名臨時物件進行 std::auto_ptr 的複製構造和賦值。由於其複製建構函式和複製賦值運算子將引數作為非 const 引用,它們不能直接繫結右值引數。然而,可以執行使用者定義的轉換 (1) 或 (2)(這會釋放原始的 auto_ptr
),然後呼叫按值接收 auto_ptr_ref
的建構函式或複製賦值運算子。這是移動語義的早期實現。