std::auto_ptr<T>::operator auto_ptr<Y>
来自 cppreference.cn
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
的构造函数或拷贝赋值运算符。这是移动语义的早期实现。