Namespaces
Variants

std::auto_ptr<T>:: operator auto_ptr<Y>

From cppreference.net
Memory management library
( exposition only* )
Allocators
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Memory resources
Uninitialized storage (until C++20)
( until C++20* )
( until C++20* )
( until C++20* )

Garbage collector support (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
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 的引用。 std::auto_ptr 可通过此模板进行 转换 赋值 。实现允许为该模板提供不同名称,或以其他方式实现等效功能。
2) 构造一个新的 auto_ptr ,其指针通过调用 release() 获得。

参数

(无)

返回值

1) 一种实现定义的类型,用于持有对 * this 的引用。
2) 一个通过调用 release() 获得指针的 auto_ptr

注释

提供来自 auto_ptr_ref 的构造函数和复制赋值运算符,是为了允许从无名临时对象复制构造和赋值 std::auto_ptr 。由于其复制构造函数和复制赋值运算符将参数作为非const引用接收,它们无法直接绑定右值参数。但可以执行用户定义的转换 (1) (2) (这会释放原始 auto_ptr ),随后调用通过值接收 auto_ptr_ref 的构造函数或复制赋值运算符。这是 移动语义 的早期实现。