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
的构造函数或复制赋值运算符。 这是 移动语义 的早期实现。