Namensräume
Varianten
Aktionen

std::unique_ptr

Aus cppreference.com
< cpp‎ | memory


 
 
 
Dynamische Speicherverwaltung
Low-Level-Speicherverwaltung
Zuweiser
Original:
Allocators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
allocator
allocator_traits(C++11)
allocator_arg_t(C++11)
allocator_arg(C++11)
uses_allocator(C++11)
scoped_allocator_adaptor(C++11)
Initialisierter Speicher
Original:
Uninitialized storage
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
uninitialized_copy
uninitialized_copy_n(C++11)
uninitialized_fill
uninitialized_fill_n
raw_storage_iterator
get_temporary_buffer
return_temporary_buffer
Intelligente Zeiger
Original:
Smart pointers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
unique_ptr(C++11)
shared_ptr(C++11)
weak_ptr(C++11)
auto_ptr(veraltet)
owner_less(C++11)
enable_shared_from_this(C++11)
bad_weak_ptr(C++11)
default_delete(C++11)
Garbage Collection Unterstützung
Original:
Garbage collection support
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
declare_reachable(C++11)
undeclare_reachable(C++11)
declare_no_pointers(C++11)
undeclare_no_pointers(C++11)
pointer_safety(C++11)
get_pointer_safety(C++11)
Verschiedenes
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
pointer_traits(C++11)
addressof(C++11)
align(C++11)
C-Bibliothek
Original:
C Library
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
std :: unique_ptr
Member-Funktionen
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
unique_ptr::unique_ptr
unique_ptr::~unique_ptr
unique_ptr::operator=
Modifiers
Original:
Modifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
unique_ptr::release
unique_ptr::reset
unique_ptr::swap
Beobachter
Original:
Observers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
unique_ptr::get
unique_ptr::get_deleter
unique_ptr::operator bool
unique_ptr::operator*
unique_ptr::operator->
unique_ptr::operator[]
Non-Member-Funktionen
Original:
Non-member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
operator==
operator!=
operator<
operator>
operator<=
operator>
operator>=
std::swap
std::hash
 
Defined in header <memory>
template<

    class T,
    class Deleter = std::default_delete<T>

> class unique_ptr;
(1) (seit C++11)
template <

    class T,
    class Deleter

> class unique_ptr<T[],Deleter>;
(2) (seit C++11)
std::unique_ptr ist ein Smart-Pointer, dass:
Original:
std::unique_ptr is a smart pointer that:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • bleibt Alleineigentum eines Objekts über einen Zeiger, und
    Original:
    retains sole ownership of an object through a pointer, and
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • zerstört die spitzen-einzuwenden, wenn die unique_ptr geht out of scope .
    Original:
    destroys the pointed-to object when the unique_ptr goes out of scope.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
unique_ptr ist nicht kopierbar oder Kopie belegbar, können zwei Instanzen von unique_ptr nicht geschafft das gleiche Objekt. Ein nicht-const unique_ptr kann das Eigentum an dem verwalteten Objekt zu einem anderen unique_ptr übertragen. Ein const std::unique_ptr können nicht übertragen werden, begrenzen die Lebensdauer des verwalteten Objekts auf den Umfang, in dem der Zeiger angelegt wurde. Wenn der unique_ptr zerstört wird, verfügt er über das Objekt durch Deleter .
Original:
unique_ptr is not copyable or copy-assignable, two instances of unique_ptr cannot manage the same object. A non-const unique_ptr can transfer the ownership of the managed object to another unique_ptr. A const std::unique_ptr cannot be transferred, limiting the lifetime of the managed object to the scope in which the pointer was created. When the unique_ptr is destroyed, it disposes of the object through Deleter.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Es gibt zwei Versionen von std::unique_ptr:
Original:
There are two versions of std::unique_ptr:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
1)
verwaltet die Lebensdauer eines einzelnen Objekts, z. B. zugeordnet mit neuen
Original:
manages the lifetime of a single object, e.g. allocated with new
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2)
verwaltet die Lebensdauer eines Arrays mit einer Laufzeit Länge, z. B. zugeordnet mit new []
Original:
manages the lifetime of an array with a runtime length, e.g. allocated with new[]
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Typische Anwendungen von std::unique_ptr gehören
Original:
Typical uses of std::unique_ptr include
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • Bereitstellung Ausnahme Sicherheit auf Klassen und Funktionen, die Objekte zu behandeln mit dynamischer Lebensdauer, durch die Gewährleistung Deletion sowohl normale Ausfahrt und Ausfahrt durch Ausnahme .
    Original:
    providing exception safety to classes and functions that handle objects with dynamic lifetime, by guaranteeing deletion on both normal exit and exit through exception.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • vorbei Eigentum einzigartig eigene Objekte mit dynamischer Lebensdauer in Funktionen
    Original:
    passing ownership of uniquely-owned objects with dynamic lifetime into functions
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • Erwerb des Eigentums von einzigartig-prozentige Objekte mit dynamischen Lebensdauer von Funktionen
    Original:
    acquiring ownership of uniquely-owned objects with dynamic lifetime from functions
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • als Elementtyp in Bewegung unterstützende Behältern wie std::vector, die Zeiger halten, um dynamisch zugeordneten Objekte, zB wenn polymorphe Verhalten gewünscht wird
    Original:
    as the element type in move-aware containers, such as std::vector, which hold pointers to dynamically-allocated objects, e.g. if polymorphic behavior is desired
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

Inhaltsverzeichnis

[Bearbeiten] Mitglied Typen

Mitglied Typ
Original:
Member type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Definition
pointer
std::remove_reference<D>::type::pointer wenn dieser Typ existiert, ansonsten T *
Original:
std::remove_reference<D>::type::pointer if that type exists, otherwise T*
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
element_type
T gelang es der Typ des Objekts dieses unique_ptr
Original:
T, the type of the object managed by this unique_ptr
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
deleter_type
Deleter die Funktion Objekt oder Lvalue Bezugnahme auf Funktion oder Funktion Objekts, vom destructor aufgerufen werden
Original:
Deleter, the function object or lvalue reference to function or to function object, to be called from the destructor
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[Bearbeiten] Member-Funktionen

baut eine neue unique_ptr
Original:
constructs a new unique_ptr
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(öffentliche Elementfunktion) [edit]
zerstört sich das verwaltete Objekt, wenn diese vorhanden ist
Original:
destructs the managed object if such is present
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(öffentliche Elementfunktion) [edit]
ordnet die unique_ptr
Original:
assigns the unique_ptr
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(öffentliche Elementfunktion) [edit]
Modifiers
Original:
Modifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
liefert einen Zeiger auf das verwaltete Objekt und gibt den Betriebskosten
Original:
returns a pointer to the managed object and releases the ownership
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(öffentliche Elementfunktion) [edit]
ersetzt das verwaltete Objekt
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.

(öffentliche Elementfunktion) [edit]
Swaps die verwalteten Objekte
Original:
swaps the managed objects
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(öffentliche Elementfunktion) [edit]
Beobachter
Original:
Observers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
liefert einen Zeiger auf das verwaltete Objekt
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.

(öffentliche Elementfunktion) [edit]
gibt die deleter, die zur Zerstörung des verwalteten Objekt verwendet wird
Original:
returns the deleter that is used for destruction of 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.

(öffentliche Elementfunktion) [edit]
prüft, ob verwalteten Objekt verknüpft ist
Original:
checks if there is associated managed object
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(öffentliche Elementfunktion) [edit]
Single-Version des Objekts, unique_ptr <T>
Original:
Single-object version, unique_ptr<T>
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
dereferences Zeiger auf das verwaltete Objekt
Original:
dereferences 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.

(öffentliche Elementfunktion) [edit]
Array-Version, unique_ptr <T[]>
Original:
Array version, unique_ptr<T[]>
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
bietet indizierten Zugriff auf das verwaltete Array
Original:
provides indexed access to the managed array
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(öffentliche Elementfunktion) [edit]

[Bearbeiten] Non-Member-Funktionen

vergleicht zu einem anderen oder mit unique_ptr nullptr
Original:
compares to another unique_ptr or with nullptr
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(Funktions-Template) [edit]
spezialisiert die std::swap Algorithmus
Original:
specializes the std::swap algorithm
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(Funktions-Template) [edit]

[Bearbeiten] Helper-Klassen

Hash-Unterstützung für std::unique_ptr
Original:
hash support for std::unique_ptr
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(class Template-Spezialisierung) [edit]

[Bearbeiten] Beispiel

#include <iostream>
#include <memory>
 
struct Foo {
    Foo() { std::cout << "Foo::Foo\n"; }
    ~Foo() { std::cout << "Foo::~Foo\n"; }
    void bar() { std::cout << "Foo::bar\n"; }
};
 
void f(const Foo &foo)
{
    std::cout << "f(const Foo&)\n";
}
 
int main()
{
    std::unique_ptr<Foo> p1(new Foo);  // p1 owns Foo
    if (p1) p1->bar();
 
    {
        std::unique_ptr<Foo> p2(std::move(p1));  // now p2 owns Foo
        f(*p2);
 
        p1 = std::move(p2);  // ownership returns to p1
        std::cout << "destroying p2...\n";
    }
 
    if (p1) p1->bar();
 
    // Foo instance is destroyed when p1 goes out of scope
}

Output:

Foo::Foo
Foo::bar
f(const Foo&)
destroying p2...
Foo::bar
Foo::~Foo