std::weak_ptr::weak_ptr
Da cppreference.com.
|
|
Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.
La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
<metanoindex/>
<tbody> </tbody> constexpr weak_ptr(); |
(1) | (dal C++11) |
weak_ptr( const weak_ptr& r ); |
(2) | (dal C++11) |
template< class Y > weak_ptr( const weak_ptr<Y>& r ); |
(2) | (dal C++11) |
template< class Y > weak_ptr( const std::shared_ptr<Y>& r ); |
(2) | (dal C++11) |
Costruisce
weak_ptr nuova che condivide potenzialmente un oggetto con 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)
Costruttore di default. Costruisce
weak_ptr vuoto.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)
Costruisce
weak_ptr nuova che condivide un oggetto gestito da r. Se r gestisce nessun oggetto, *this gestisce nessun oggetto troppo. Gli overload basate su modelli non prende parte alla risoluzione di sovraccarico a meno Y* la conversione implicita in 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.
Parametri
| r | - | un std::shared_ptr o std::weak_ptr che verrà visualizzato da questo 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. |
Eccezioni
Esempio
#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';
}
Output:
w_ptr.use_count() inside scope: 1
w_ptr.use_count() out of scope: 0
Vedi anche
assegna il weak_ptrOriginal: assigns the weak_ptrThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (metodo pubblico) | |