std::shared_ptr
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. |
| Defined in header <memory>
|
||
| template< class T > class shared_ptr; |
(seit C++11) | |
std::shared_ptr ist ein intelligenter Zeiger, der gemeinsamen Trägerschaft eines Objekts über einen Zeiger behält. Mehrere shared_ptr Objekte besitzen darf das gleiche Objekt, das Objekt zerstört wird, wenn der letzte verbleibende shared_ptr auf sie zeigen zerstört oder zurückzusetzen. Das Objekt zerstört wird mit delete-expression oder eine benutzerdefinierte deleter, die shared_ptr während der Bauphase geliefert wird .Original:
std::shared_ptr is a smart pointer that retains shared ownership of an object through a pointer. Several shared_ptr objects may own the same object; the object is destroyed when the last remaining shared_ptr pointing to it is destroyed or reset. The object is destroyed using delete-expression or a custom deleter that is supplied to shared_ptr during construction.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.
A
shared_ptr kann auch besitzen keine Objekte, in diesem Fall wird er als leer .Original:
A
shared_ptr may also own no objects, in which case it is called empty.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.
shared_ptr erfüllt die Anforderungen der CopyConstructible und CopyAssignable .Original:
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.
[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 |
| element_type | T |
[Bearbeiten] Member-Funktionen
constructs new shared_ptr (öffentliche Elementfunktion) | |
| zerstört sich die Besitz-Objekt, wenn nicht mehr shared_ptrs verlinken Original: destructs the owned object if no more shared_ptrs link to it The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (öffentliche Elementfunktion) | |
| ordnet die shared_ptr Original: assigns the shared_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) | |
Original: Modifiers The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
| 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) | |
| 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) | |
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) | |
| 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) | |
| gibt die Anzahl der Objekte shared_ptr auf dieselbe verwalteten Objekts Original: returns the number of shared_ptr objects referring to the same 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) | |
| prüft, ob das verwaltete Objekt ist nur durch die aktuelle shared_ptr Instanz verwaltet Original: checks whether the managed object is managed only by the current shared_ptr instance The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (öffentliche Elementfunktion) | |
| 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) | |
| bietet Inhaber-basierte Bestellsystem der geteilten Zeiger Original: provides owner-based ordering of shared pointers The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (öffentliche Elementfunktion) | |
[Bearbeiten] Non-Member-Funktionen
| schafft eine gemeinsame Zeiger, der ein neues Objekt verwaltet Original: creates a shared pointer that manages a new object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (Funktions-Template) | |
| schafft eine gemeinsame Zeiger, der ein neues Objekt zugewiesen werden, indem eine Allocator verwaltet Original: creates a shared pointer that manages a new object allocated using an allocator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (Funktions-Template) | |
| static_cast gilt, dynamic_cast oder const_cast dem Typ des verwalteten Objekts Original: The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (Funktions-Template) | |
| gibt die deleter des angegebenen Typs, wenn Besitz Original: returns the deleter of specified type, if owned The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (Funktions-Template) | |
| vergleicht mit einem anderen oder mit shared_ptr nullptr Original: compares with another shared_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) | |
| gibt den Wert des verwalteten Zeiger auf einen Ausgabestrom Original: outputs the value of the managed pointer to an output stream The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (Funktions-Template) | |
| (C++11) |
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) |
| spezialisiert atomare Operationen Original: specializes atomic operations The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (Funktions-Template) | |
[Bearbeiten] Helper-Klassen
| (C++11) |
Hash-Unterstützung für std::shared_ptr Original: hash support for std::shared_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) |
[Bearbeiten] Hinweise zur Umsetzung
In einer typischen Implementierung hält std::shared_ptr nur zwei Zeigern:
Original:
In a typical implementation, std::shared_ptr holds only two pointers:
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.
- ein Pointer auf das referenzierte ObjektOriginal:a pointer to the referenced objectThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - ein Zeiger auf SteuerblockOriginal:a pointer to control blockThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Wo der Steuerblock ist ein dynamisch-zugewiesene Objekt, gilt:
Original:
Where the control block is a dynamically-allocated object that holds:
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.
- ein Zeiger auf das verwaltete Objekt oder dem verwalteten ObjektOriginal:a pointer to the managed object or the managed object itselfThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Die deleterOriginal:the deleterThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - der VerteilerOriginal:the allocatorThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - die Zahl der
shared_ptrs, die das verwaltete Objekt besitzenOriginal:the number ofshared_ptrs that own the managed objectThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - die Anzahl der
weak_ptrs, die das verwaltete Objekt beziehenOriginal:the number ofweak_ptrs that refer to the managed objectThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Wenn
shared_ptr indem erstellt std::make_shared oder std::allocate_shared der Steuerblock hält das verwaltete Objekt direkt als Daten-Mitglied. Wenn shared_ptr durch den Aufruf eines Konstruktors erstellt wird, wird ein Zeiger gespeichert .Original:
When
shared_ptr is created by calling std::make_shared or std::allocate_shared, the control block holds the managed object directly, as a data member. When shared_ptr is created by calling a constructor, a pointer is stored.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.
Der Zeiger des
shared_ptr direkt gehalten ist, die durch get() zurückgegeben, während der Zeiger / Gegenstand durch den Steuerblock gehalten ist diejenige, die gelöscht werden, wenn die Anzahl der gemeinsamen Eigentümer Null erreicht wird: diese Zeiger sind nicht notwendigerweise gleich .Original:
The pointer held by the
shared_ptr directly is the one returned by get(), while the pointer/object held by the control block is the one that will be deleted when the number of shared owners reaches zero: these pointers are not necessarily equal.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.
Die Destruktor
shared_ptr dekrementiert die Anzahl der gemeinsam Eigentümer des Steuerblocks, und wenn das Null erreicht, ruft der Steuerblock die destructor des verwalteten Objekts, sondern der Steuerblock nicht deallocate selbst, bis der Zähler gleich Null ist std::weak_ptr als auch .Original:
The destructor of
shared_ptr decrements the number of shared owners of the control block, and if that reaches zero, the control block calls the destructor of the managed object, but the control block does not deallocate itself until the std::weak_ptr counter reaches zero as well.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.