Espaços nominais
Variantes
Acções

std::weak_ptr

Da cppreference.com
< cpp‎ | memory

 
 
Biblioteca de utilitários
Digite apoio (basic types, RTTI, type traits)
Gerenciamento de memória dinâmica
De tratamento de erros
Utilidades do programa
Variadic funções
Data e hora
Objetos de função
(C++11)
Os operadores relacionais
Original:
Relational operators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
rel_ops::operator!=
rel_ops::operator>
rel_ops::operator<=
rel_ops::operator>=
Pares e tuplas
Original:
Pairs and tuples
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
Troque, avançar e avançar
Original:
Swap, forward and move
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
(C++11)
(C++11)
 
Gerenciamento de memória dinâmica
Gerenciamento de memória de baixo nível
Alocadores
Original:
Allocators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Uninitialized armazenamento
Original:
Uninitialized storage
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Ponteiros inteligentes
Original:
Smart pointers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
(C++11)
weak_ptr
(C++11)
(obsoleta)
(C++11)
Apoio a coleta de lixo
Original:
Garbage collection support
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Diversos
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
(C++11)
C Library
Original:
C Library
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
std::weak_ptr
Funções de membro
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.
weak_ptr::weak_ptr
weak_ptr::~weak_ptr
weak_ptr::operator=
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.
weak_ptr::reset
weak_ptr::swap
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.
weak_ptr::use_count
weak_ptr::expired
weak_ptr::lock
weak_ptr::owner_before
Não-membros funções
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 no cabeçalho <memory>
template<class T >class weak_ptr;
(desde C++11)
std::weak_ptr é um ponteiro inteligente que contém um não-proprietária de referência ("fraco") a um objeto que é gerenciado pelo std::shared_ptr. Ele deve ser convertido para std::shared_ptr para acessar o objeto referenciado.
Original:
std::weak_ptr is a smart pointer that holds a non-owning ("weak") reference to an object that is managed by std::shared_ptr. It must be converted to std::shared_ptr in order to access 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.
std::weak_ptr modelos de propriedade temporária:. quando um objeto precisa ser acessado somente se ele existe, e ele pode ser excluído a qualquer momento por outra pessoa, std::weak_ptr é usado para rastrear o objeto, e ele é convertido para std::shared_ptr para assumir a propriedade temporária. std::shared_ptr Se o original é destruído neste momento, a vida útil do objeto é prorrogado até o std::shared_ptr temporário é destruído, bem.
Original:
std::weak_ptr models temporary ownership: when an object needs to be accessed only if it exists, and it may be deleted at any time by someone else, std::weak_ptr is used to track the object, and it is converted to std::shared_ptr to assume temporary ownership. If the original std::shared_ptr is destroyed at this time, the object's lifetime is extended until the temporary std::shared_ptr is destroyed as well.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Além disso, std::weak_ptr é usado para quebrar as referências circulares de std::shared_ptr.
Original:
In addition, std::weak_ptr is used to break circular references of 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.

Índice

[editar]Tipos de membro

Tipo de membro
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_typeT

[editar]Funções de membro

cria um novo weak_ptr
Original:
creates a new weak_ptr
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(função pública membro)[edit]
destrói uma weak_ptr
Original:
destroys a weak_ptr
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(função pública membro)[edit]
atribui o weak_ptr
Original:
assigns the weak_ptr
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(função pública membro)[edit]
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.
libera a propriedade do objeto gerenciado
Original:
releases the 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.

(função pública membro)[edit]
troca os objetos gerenciados
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.

(função pública membro)[edit]
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.
retorna o número de objetos shared_ptr que gerenciam o objeto
Original:
returns the number of shared_ptr objects that manage the object
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(função pública membro)[edit]
Verifica se o objeto referenciado já foi excluído
Original:
checks whether the referenced object was already deleted
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(função pública membro)[edit]
cria um shared_ptr que gerencia o objeto referenciado
Original:
creates a shared_ptr that manages 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.

(função pública membro)[edit]
fornece-proprietário baseado ordenação dos ponteiros fracos
Original:
provides owner-based ordering of weak pointers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(função pública membro)[edit]

[editar]Não-membros funções

o algoritmo especializado 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.

(modelo de função)[edit]

[editar]Exemplo

Demonstra como bloqueio é usado para garantir a validade do ponteiro .
Original:
Demonstrates how lock is used to ensure validity of the pointer.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <iostream>#include <memory>   std::weak_ptr<int> gw;   void f(){if(auto spt = gw.lock()){// Has to be copied into a shared_ptr before usagestd::cout<<*spt <<"\n";}else{std::cout<<"gw is expired\n";}}   int main(){{auto sp =std::make_shared<int>(42); gw = sp;   f();}   f();}

Saída:

42 gw is expired
close