std::unique_ptr::operator=
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> unique_ptr& operator=( unique_ptr&& r ); |
(1) | (dal C++11) |
template< class U, class E > unique_ptr& operator=( unique_ptr<U,E>&& r ); |
(1) | (dal C++11) |
unique_ptr& operator=( nullptr_t ); |
(2) | (dal C++11) |
1)
Trasferimento di proprietà dell'oggetto puntato da
r a *this come se chiamando reset(r.release()) seguito da un incarico da std::forward<E>(r.get_deleter()). Original:
Transfers ownership of the object pointed to by
r to *this as if by calling reset(r.release()) followed by an assignment from std::forward<E>(r.get_deleter()). 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)
In effetti la stessa chiamata
reset().Original:
Effectively the same as calling
reset().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.
Si noti che l'operatore di assegnazione di
unique_ptr accetta solo XValues, che vengono tipicamente generati da std::move. (La classe unique_ptr esplicitamente cancella il suo costruttore di copia lvalue e assegnazione lvalue.)Original:
Note that
unique_ptr's assignment operator only accepts XValues, which are typically generated by std::move. (The unique_ptr class explicitly deletes its lvalue copy constructor and lvalue assignment operator.)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 | - | puntatore intelligente da cui proprietà sarà trasferita
Original: smart pointer from which ownership will be transfered The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Valore di ritorno
*this
Eccezioni
Esempio
#include <iostream>
#include <memory>
struct Foo {
Foo() { std::cout << "Foo\n"; }
~Foo() { std::cout << "~Foo\n"; }
};
int main()
{
std::unique_ptr<Foo> p1;
{
std::cout << "Creating new Foo...\n";
std::unique_ptr<Foo> p2(new Foo);
p1 = std::move(p2);
std::cout << "About to leave inner block...\n";
// Foo instance will continue to live,
// despite p2 going out of scope
}
std::cout << "About to leave program...\n";
}
Output:
Creating new Foo...
Foo
About to leave inner block...
About to leave program...
~Foo