std::weak_ptr::weak_ptr
De cppreference.com
<metanoindex/>
<tbody> </tbody> 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
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.
1)
Construtor padrão. Constrói
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.
2)
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.
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. |
Exceções
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
