std::unique_ptr::release
De 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. |
<metanoindex/>
<tbody> </tbody> 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.
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.
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.
Exceptions
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
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) | |