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(); |
(desde C++11) | |
Libera a propriedade do objeto gerenciado se houver.
get() retornos nullptr após a chamada.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.
Parâmetros
(Nenhum)
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.
Valor de retorno
Ponteiro para o objeto gerenciado ou
nullptr se não houvesse objeto gerenciado, ou seja, o valor que seria devolvido por get() antes da chamada.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.
Exceções
Exemplo
#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;
}
Saída:
Creating new Foo...
Foo
About to release Foo...
Foo is no longer owned by unique_ptr...
~Foo
Veja também
retorna um ponteiro para o objeto gerenciado 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. (função pública membro) | |
substitui o objeto gerenciado 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. (função pública membro) | |