std::shared_ptr
De 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. |
| Definido en la cabecera <memory>
|
||
| template< class T > class shared_ptr; |
(desde C++11) | |
std::shared_ptr es un puntero inteligente que mantiene la propiedad compartida de un objeto a través de un puntero. Varios objetos shared_ptr pueden poseer el mismo objeto, el objeto se destruye cuando el shared_ptr último que queda apuntando a que se destruye o se restablece. El objeto se destruye usando delete-expression o un Deleter personalizado que se suministra a shared_ptr durante la construcción .Original:
std::shared_ptr is a smart pointer that retains shared ownership of an object through a pointer. Several shared_ptr objects may own the same object; the object is destroyed when the last remaining shared_ptr pointing to it is destroyed or reset. The object is destroyed using delete-expression or a custom deleter that is supplied to shared_ptr during construction.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.
Un
shared_ptr también puede poseer ningún objeto, en cuyo caso se llama vacío .Original:
A
shared_ptr may also own no objects, in which case it is called empty.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.
shared_ptr cumple los requisitos de CopyConstructible y CopyAssignable .Original:
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.
[editar] Tipos de miembros
| Miembro de tipo
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 |
[editar] Las funciones miembro
constructs new shared_ptr (función miembro público) | |
| destruye la propiedad del objeto si no hay vínculo más shared_ptrs a ella Original: destructs the owned object if no more shared_ptrs link to it The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (función miembro público) | |
| asigna el shared_ptr Original: assigns the shared_ptr The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (función miembro público) | |
Original: Modifiers The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
| reemplaza el objeto administrado Original: replaces 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. (función miembro público) | |
| intercambia los objetos gestionados Original: swaps the managed objects The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (función miembro público) | |
Original: Observers The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
| devuelve un puntero al objeto gestionado Original: returns 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. (función miembro público) | |
| desreferencia de puntero al objeto gestionado (función miembro público) | |
| devuelve el número de objetos que se refieren a la shared_ptr objeto gestionado mismo Original: returns the number of shared_ptr objects referring to the same managed object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (función miembro público) | |
| Comprueba si el objeto administrado es manejado sólo por la instancia shared_ptr actual Original: checks whether the managed object is managed only by the current shared_ptr instance The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (función miembro público) | |
| comprueba si se asocia objeto administrado Original: checks if there is associated managed object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (función miembro público) | |
| proporciona propietario basado pedido de punteros compartidos Original: provides owner-based ordering of shared pointers The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (función miembro público) | |
[editar] Terceros funciones
| crea un puntero compartido que gestiona un nuevo objeto Original: creates a shared pointer that manages a new object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (plantilla de función) | |
| crea un puntero compartido que gestiona un nuevo objeto asignado usando un asignador Original: creates a shared pointer that manages a new object allocated using an allocator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (plantilla de función) | |
| aplica static_cast, dynamic_cast o const_cast para el tipo de objeto administrado Original: The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (plantilla de función) | |
| devuelve el Deleter del tipo especificado, si poseía Original: returns the deleter of specified type, if owned The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (plantilla de función) | |
compara con otro shared_ptr o con nullptr (plantilla de función) | |
| emite el valor del puntero administrado a un flujo de salida Original: outputs the value of the managed pointer to an output stream The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (plantilla de función) | |
| (C++11) |
el algoritmo se especializa std::swap Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (plantilla de función) |
| se especializa operaciones atómicas Original: specializes atomic operations The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (plantilla de función) |
[editar] Clases de ayuda
| (C++11) |
apoyo hash para std::shared_ptr Original: hash support for std::shared_ptr The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (especialización de plantilla de clase) |
[editar] Notas de aplicación
En una implementación típica, std::shared_ptr tiene sólo dos punteros:
Original:
In a typical implementation, std::shared_ptr holds only two pointers:
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.
- un puntero para el objeto de referenciaOriginal:a pointer to the referenced objectThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - un puntero a' bloque de controlOriginal:a pointer to control blockThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Cuando el bloque de control es un objeto asignados de forma dinámica que contiene:
Original:
Where the control block is a dynamically-allocated object that holds:
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.
- un puntero al objeto gestionado o administrado el objeto en síOriginal:a pointer to the managed object or the managed object itselfThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - el DeleterOriginal:the deleterThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - el asignadorOriginal:the allocatorThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - el número de
shared_ptrs que poseen el objeto administradoOriginal:the number ofshared_ptrs that own the managed objectThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - el número de
weak_ptrs que se refieren al objeto administradoOriginal:the number ofweak_ptrs that refer to the managed objectThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Cuando
shared_ptr se crea llamando std::make_shared o std::allocate_shared, el bloque de control contiene el objeto administrado directamente, como un miembro de datos. Cuando shared_ptr se crea llamando a un constructor, un puntero se guarda .Original:
When
shared_ptr is created by calling std::make_shared or std::allocate_shared, the control block holds the managed object directly, as a data member. When shared_ptr is created by calling a constructor, a pointer is stored.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.
El puntero del poder del
shared_ptr directamente es la devuelta por get(), mientras que el puntero / object poder del bloque de control es el que se eliminarán cuando el número de propietarios compartidas llega a cero: estos indicadores no son necesariamente iguales .Original:
The pointer held by the
shared_ptr directly is the one returned by get(), while the pointer/object held by the control block is the one that will be deleted when the number of shared owners reaches zero: these pointers are not necessarily equal.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.
El destructor de
shared_ptr disminuye el número de propietarios compartidos del bloque de control y, en caso de que llegue a cero, el bloque de control llama al destructor del objeto gestionado, pero el bloque de control no se desasigna hasta que el contador llegue a cero std::weak_ptr también .Original:
The destructor of
shared_ptr decrements the number of shared owners of the control block, and if that reaches zero, the control block calls the destructor of the managed object, but the control block does not deallocate itself until the std::weak_ptr counter reaches zero as well.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.

