std::unique_ptr::operator=
Aus 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> unique_ptr& operator=( unique_ptr&& r ); |
(1) | (seit C++11) |
template< class U, class E > unique_ptr& operator=( unique_ptr<U,E>&& r ); |
(1) | (seit C++11) |
unique_ptr& operator=( nullptr_t ); |
(2) | (seit C++11) |
1)
Transfers Eigentum an dem Gegenstand, auf den
r um *this, als ob durch den Aufruf reset(r.release()) durch eine Zuweisung von std::forward<E>(r.get_deleter()) gefolgt. 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)
Effektiv das gleiche wie der Aufruf
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.
Beachten Sie, dass die
unique_ptr Zuweisungsoperator akzeptiert nur XValues, die typischerweise durch std::move erzeugt. (Der unique_ptr Klasse explizit löscht seine lvalue Copy-Konstruktor und lvalue Zuweisungsoperator.)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.
Parameter
| r | - | Smart-Pointer aus dem Eigentum übertragen werden
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. |
Rückgabewert
*this
Ausnahmen
Beispiel
#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