std::unique_ptr::release
Da cppreference.com.
< cpp | memory | unique ptr
![]() |
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. |
pointer release(); |
(dal C++11) | |
Rilascia la proprietà dell'oggetto gestito se presente.
get()
ritorna nullptr dopo la chiamata.Original:
Releases the ownership of the managed object if any.
get()
returns nullptr after the call.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.
Indice |
[modifica] Parametri
(Nessuno)
Original:
(none)
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.
[modifica] Valore di ritorno
Puntatore l'oggetto gestito o nullptr se non ci fosse oggetto gestito, cioè il valore che sarebbe tornato dal
get()
prima della chiamata.Original:
Pointer to the managed object or nullptr if there was no managed object, i.e. the value which would be returned by
get()
before the call.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.
[modifica] Eccezioni
[modifica] Esempio
#include <memory> #include <iostream> struct Foo { Foo() { std::cout << "Foo\n"; } ~Foo() { std::cout << "~Foo\n"; } }; int main() { std::cout << "Creating new Foo...\n"; std::unique_ptr<Foo> up(new Foo()); std::cout << "About to release Foo...\n"; Foo* fp = up.release(); if (up.get() == nullptr) std::cout << "Foo is no longer owned by unique_ptr...\n"; delete fp; }
Output:
Creating new Foo... Foo About to release Foo... Foo is no longer owned by unique_ptr... ~Foo
[modifica] Vedi anche
restituisce un puntatore all'oggetto gestito 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. (metodo pubblico) | |
sostituisce l'oggetto gestito 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. (metodo pubblico) |