std::auto_ptr
来自cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| Defined in header <memory>
|
||
| template< class T > class auto_ptr; |
(1) | (过时了) |
| template<> class auto_ptr<void> |
(2) | (过时了) |
auto_ptr是一个智能指针,通过新的管理对象和删除对象时,auto_ptr本身被破坏。它可用于动态分配的对象,拥有动态分配的对象传递到函数,从函数返回动态分配的对象提供异常安全.Original:
auto_ptr is a smart pointer that manages an object obtained via new and deletes that object when auto_ptr itself is destroyed. It may be used to provide exception safety for dynamically-allocated objects, for passing ownership of dynamically-allocated objects into functions and for returning dynamically-allocated objects from functions.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
复制
2) auto_ptr复制指针和所有权转移的目的地:auto_ptr拷贝构造函数和拷贝赋值修改自己的右手参数,并且不等于原来的“复制”。由于这些不寻常的拷贝语义,auto_ptr可能不会被放置在标准的容器。 std::unique_ptr优选这和其他用途.Original:
Copying an
auto_ptr copies the pointer and transfers ownership to the destination: both copy construction and copy assignment of auto_ptr modify their right hand arguments, and the "copy" is not equal to the original. Because of these unusual copy semantics, auto_ptr may not be placed in standard containers. std::unique_ptr is preferred for this and other uses.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
提供专业化的类型void,它声明的的类型定义
element_type,但没有成员函数.Original:
Specialization for type void is provided, it declares the typedef
element_type, but no member functions.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 会员类型
| 会员类型
Original: Member type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Definition |
| element_type | T |
[编辑] 成员函数
| 创建一个新的auto_ptr的 Original: creates a new auto_ptr The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数) | |
| 破坏一个auto_ptr和管理的对象 Original: destroys an auto_ptr and the managed object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数) | |
| 从另一个auto_ptr的所有权转让 Original: transfers ownership from another auto_ptr The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数) | |
| 托管指针转换到不同类型的指针 Original: converts the managed pointer to a pointer to different type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数) | |
Original: Modifiers The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
| 破坏了管理对象 Original: destroys the managed object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数) | |
| 释放管理对象的所有权 Original: releases ownership of the managed object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数) | |
Original: Observers The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
| 获取管理对象的指针 Original: obtains a pointer to the managed object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数) | |
| 访问管理的对象 Original: accesses the managed object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数) | |