std::weak_ptr::weak_ptr
Da 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. |
constexpr weak_ptr(); |
(1) | (desde C++11) |
weak_ptr( const weak_ptr& r ); |
(2) | (desde C++11) |
template< class Y > weak_ptr( const weak_ptr<Y>& r ); |
(2) | (desde C++11) |
template< class Y > weak_ptr( const std::shared_ptr<Y>& r ); |
(2) | (desde C++11) |
Constrói
1) weak_ptr
novo que potencialmente partes de um objeto com r
.Original:
Constructs new
weak_ptr
that potentially shares an object with r
.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.
Construtor padrão. Constrói
2) weak_ptr
vazio.Original:
Default constructor. Constructs empty
weak_ptr
.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.
Constrói
weak_ptr
nova, que compartilha um objeto gerenciado pelo r
. Se r
gere nenhum objeto, *this gere nenhum objeto também. As sobrecargas templated não participar na resolução de sobrecarga, a menos Y*
é implicitamente conversível para T*
. Original:
Constructs new
weak_ptr
which shares an object managed by r
. If r
manages no object, *this manages no object too. The templated overloads don't participate in the overload resolution unless Y*
is implicitly convertible to T*
. 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.
Índice |
[editar] Parâmetros
r | - | um std::shared_ptr ou std::weak_ptr que será visto por este std::weak_ptr
Original: a std::shared_ptr or std::weak_ptr that will be viewed by this std::weak_ptr The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[editar] Exceções
[editar] Exemplo
#include <memory> #include <iostream> struct Foo {}; int main() { std::weak_ptr<Foo> w_ptr; { auto ptr = std::make_shared<Foo>(); w_ptr = ptr; std::cout << "w_ptr.use_count() inside scope: " << w_ptr.use_count() << '\n'; } std::cout << "w_ptr.use_count() out of scope: " << w_ptr.use_count() << '\n'; }
Saída:
w_ptr.use_count() inside scope: 1 w_ptr.use_count() out of scope: 0
[editar] Veja também
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) |