std::unique_ptr::release
De cppreference.com
< cpp | memory | unique ptr
![]() |
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. |
pointer release(); |
(depuis C++11) | |
Communiqués de la propriété de l'objet géré le cas échéant.
get()
retours nullptr après l'appel .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.
Sommaire |
[modifier] Paramètres
(Aucun)
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.
[modifier] Retourne la valeur
Pointeur sur l'objet géré ou nullptr s'il n'y avait pas d'objet géré, c'est à dire la valeur qui serait retourné par
get()
avant l'appel .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.
[modifier] Exceptions
[modifier] Exemple
#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; }
Résultat :
Creating new Foo... Foo About to release Foo... Foo is no longer owned by unique_ptr... ~Foo
[modifier] Voir aussi
renvoie un pointeur sur l'objet géré 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. (fonction membre publique) | |
remplace l'objet géré 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. (fonction membre publique) |