std::unique_ptr::swap
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> void swap(unique_ptr& other); |
(dal C++11) | |
Swap gli oggetti gestiti e deleters associati con un altro oggetto
unique_ptr other.Original:
Swaps the managed objects and associated deleters with another
unique_ptr object other.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
| other | - | un altro oggetto
unique_ptr di scambiare l'oggetto gestito e il deleter conOriginal: another unique_ptr object to swap the managed object and the deleter withThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Valore di ritorno
(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.
Eccezioni
Esempio
#include <iostream>
#include <memory>
struct Foo {
Foo(int _val) : val(_val) { std::cout << "Foo...\n"; }
~Foo() { std::cout << "~Foo...\n"; }
int val;
};
int main()
{
std::unique_ptr<Foo> up1(new Foo(1));
std::unique_ptr<Foo> up2(new Foo(2));
up1.swap(up2);
std::cout << "up1->val:" << up1->val << std::endl;
std::cout << "up2->val:" << up2->val << std::endl;
}
Output:
Foo...
Foo...
up1->val:2
up2->val:1
~Foo...
~Foo...