首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::auto_ptr

Defined in header <memory>

template< class T > class auto_ptr;

(1)

(until C++17) (deprecated since C++11)

template<> class auto_ptr<void>;

(2)

(until C++17) (deprecated since C++11)

auto_ptr是一个智能指针,它管理通过新表达式并在下列情况下删除该对象:auto_ptr它本身就被摧毁了。它可以用于为动态分配的对象提供异常安全,用于将动态分配对象的所有权传递给函数,以及从函数返回动态分配的对象。

复制auto_ptr复制指针并将所有权传递给目标:复制构造和复制分配auto_ptr修改他们的右手参数,而“副本”并不等于原件。因为这些不寻常的复制语义,auto_ptr不能放置在标准容器中。std::unique_ptr用于此用途和其他用途。%28自C++11%29。

2%29类型专业化void,则声明element_type,但没有成员功能。

额外的类模板auto_ptr_ref在整个文档中都会提到。它是一个实现定义类型,包含对auto_ptr该实现允许为模板提供不同的名称,或者以其他方式实现返回它或接受它作为参数的函数。

成员类型

Member type

Definition

element_type

T

成员函数

(constructor)

creates a new auto_ptr (public member function)

(destructor)

destroys an auto_ptr and the managed object (public member function)

operator=

transfers ownership from another auto_ptr (public member function)

operator auto_ptr<Y>operator auto_ptr_ref<Y>

converts the managed pointer to a pointer to different type (public member function)

观察员

GET返回指向托管对象%28公共成员函数%29的指针

操作者%2A操作符->访问托管对象%28公共成员函数%29

修饰符

重置破坏托管对象%28公共成员函数%29

发布发布托管对象%28公共成员函数%29的所有权

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券