X Tutup
The Wayback Machine - https://web.archive.org/web/20210506181241/https://es.cppreference.com/w/cpp/memory/shared_ptr
Espacios de nombres
Variantes
Acciones

std::shared_ptr

De cppreference.com
< cpp‎ | memory
 
 
 
Gestión de memoria dinámica
Punteros inteligentes
(C++11)
shared_ptr
(C++11)
(C++11)
(hasta C++17)
(C++11)
Asignadores
Recursos de memoria
Almacenamiento no inicializado
Soporte de recolección de basura
Misceláneos
(C++20)
(C++11)
(C++11)
Biblioteca de C
Administración de memoria de bajo nivel
 
std::shared_ptr
Las funciones miembro
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Modificadores
Original:
Modifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Los observadores
Original:
Observers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Terceros funciones
Original:
Non-member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
Definido en el archivo de encabezado <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.
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.
shared_ptr cumple los requisitos de CopyConstructible y CopyAssignable .
Original:
shared_ptr meets the requirements of CopyConstructible and CopyAssignable.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Contenido

[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ública) [editar]
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ública) [editar]
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ública) [editar]
Modificadores
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ública) [editar]
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ública) [editar]
Los observadores
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ública) [editar]
desreferencia de puntero al objeto gestionado
(función miembro pública) [editar]
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ública) [editar]
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ública) [editar]
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ública) [editar]
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ública) [editar]

[editar] Terceros funciones

Crea un puntero compartido que gestiona un nuevo objeto.
(plantilla de función) [editar]
Crea un puntero compartido que gestiona un nuevo objeto asignado usando un asignador.
(plantilla de función) [editar]
Aplica static_cast, dynamic_cast, const_cast, o reinterpret_cast al puntero almacenado.
(plantilla de función) [editar]
Devuelve el eliminador del tipo especificado, si se posee.
(plantilla de función) [editar]
(eliminado en C++20)(eliminado en C++20)(eliminado en C++20)(eliminado en C++20)(eliminado en C++20)(C++20)
Se compara con otro
shared_ptr o con nullptr.  
(plantilla de función) [editar]
Emite el valor del puntero almacenado a un flujo de salida.
(plantilla de función) [editar]
Especializa el algoritmo std::swap.
(plantilla de función) [editar]
Especializa las operaciones atómicas para std::shared_ptr
(plantilla de función) [editar]

[editar] Clases de ayuda

Soporte hash para std::shared_ptr.
(especialización de plantilla de clase) [editar]

[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.
  • un puntero para el objeto de referencia
    Original:
    a pointer to the referenced object
    The 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 control
    Original:
    a pointer to control block
    The 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.
  • un puntero al objeto gestionado o administrado el objeto en sí
    Original:
    a pointer to the managed object or the managed object itself
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • el Deleter
    Original:
    the deleter
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • el asignador
    Original:
    the allocator
    The 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 administrado
    Original:
    the number of shared_ptrs that own 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.
  • el número de weak_ptrs que se refieren al objeto administrado
    Original:
    the number of weak_ptrs that refer 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.
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.
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.
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.
X Tutup