new expression
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/>
Initialisiert Objekte dynamisch erhalten Speicher .
Original:
Initializes objects in dynamically obtained memory.
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.
Dort eingesetzt, wo Daten dynamisch zugewiesen werden müssen, das heißt, ohne zu wissen, seine Größe vor der Zusammenstellung .
Original:
Used where data need to be allocated dynamically, that is, without knowing its size prior the compilation.
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.
Syntax
::(optional)
|
new
|
type | [array_n](optional)
|
(init_params)(optional)
|
(1) | ||||
::(optional)
|
new
|
(type )
|
[array_n](optional)
|
(init_params)(optional)
|
(2) | ||||
::(optional)
|
new
|
(placement_params)
|
type | [array_n](optional)
|
(init_params)(optional)
|
(3) | |||
::(optional)
|
new
|
(placement_params)
|
(type )
|
[array_n](optional)
|
(init_params)(optional)
|
(4) | |||
Alle Versionen geben ein Objekt vom Typ' 'type * .
Original:
All versions return an object of type type *.
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.
Erklärung
Die
new Ausdruck weist einen Speicherbereich initialisiert entweder einzelnes Objekt oder ein Array von Objekten gibt und gibt einen Zeiger auf das erste konstruiertes Objekt. Da es nicht anders möglich explizit aufrufen rufen Sie einen Konstruktor, ist der Ausdruck der einzige Weg, um ein Objekt dynamisch zu konstruieren .Original:
The
new expression allocates a memory area, initializes either single object, or an array of objects there and returns a pointer to the first constructed object. Since it is not otherwise possible to call explicitly call a constructor, the expression is the only way to construct an object dynamically.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 ersten beiden und die letzten beiden Versionen des Ausdrucks nur syntaktisch unterscheiden. Das Verhalten ist das gleiche .
Original:
The first two and last two versions of the expression differ only syntactically. The behavior is the same.
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.
| This section is incomplete Reason: Explanation about how types are specified is missing |
Speicherzuweisung
Der Speicher wird durch eine Allokation Funktion zugeordnet, entweder
operator new oder operator new[] .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.
Die letzten beiden Versionen des Ausdrucks werden als' 'placement neue und werden verwendet, um zusätzliche Parameter (placement_params) die Zuteilung Funktion übergeben .
Original:
The last two versions of the expression are called placement new and are used to pass additional parameters (placement_params) to the allocation function.
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.
Wenn array_n abwesend ist, wird der Speicher für ein einzelnes Objekt durch Aufruf
operator new Allokation Funktion zugeordnet. Ansonsten Speicher für ein Array von array_n Objekten wird durch den Aufruf operator new[] Zuteilungsfunktion zugeordnet. Man beachte, dass mehr als size_of( type ) * array_n möglicherweise aufgrund von Zusatzinformationen von dem Compiler kodiert (z. B. die Größe des Arrays, da diese Informationen benötigt, um die Objekte destruct im Array richtig) zugeordnet werden .Original:
If array_n is absent, memory is allocated for a single object by invoking
operator new allocation function. Otherwise memory for an array of array_n objects is allocated by calling operator new[] allocation function. Note, that more than size_of( type ) * array_n might be allocated because of additional information encoded by the compiler (such as the size of the array, since this information is needed in order to destruct the objects in the array properly).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 Zuordnung Funktion wird der Name zunächst in der lokalen Klasse type Rahmen gesucht und nur dann, wenn die Suche fehlschlägt, wird die globale Namensraum wird blickte auf. Wenn
<tbody>
</tbody>:: in der new Ausdruck ist, wird nur die globalen Namensraum blickte auf. Der Prototyp der Funktion sollte wie folgt aussehen, um die Zuteilung Funktion gewählt werden: Original:
The allocation function's name is firstly looked up in the local class type scope and only if the lookup fails, the global namespace is looked up. If
:: is present in the new expression, only the global namespace is looked up. The prototype of the function should look like the following in order to the allocation function to be selected: 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.
void* operator new (size_t count); |
for versions 1, 2, array_n is not present | |
void* operator new[](size_t count); |
for versions 1, 2, array_n is present | |
void* operator new (size_t count/*, placement_params...*/); |
for versions 3, 4 (placement new), array_n is not present | |
void* operator new[](size_t count/*, placement_params...*/); |
for versions 3, 4 (placement new), array_n is present | |
count ist Byteanzahl zuzuweisen, sind die Parameter angegeben placement_params der Platzierung' neuen Ausdruck .Original:
count is number of bytes to allocate, placement_params are the parameters given to the placement new expression.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.
Standard-Implementierungen und Überlastung
Mehrere Standard-Zuweisung Funktionen sind implizit in jeder Übersetzungseinheit erklärt. Außerdem sind impliziten Implementierungen vom Compiler standardmäßig vorgesehen, es sei denn, das Programm hat sie ausdrücklich umgesetzt. Diese Funktionen sind wie folgt (siehe dies für weitere Informationen):
<tbody>
</tbody>Original:
Several default allocation functions are implicitly declared in each translation unit. Also, implicit implementations are provided by the compiler by default, unless the program has explicitly implemented them. These functions are as follows (see dies for more information):
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.
void* operator new (size_t); |
(1) | |
void* operator new[](size_t); |
(2) | |
void* operator new (size_t, std::nothrow_t); |
(3) | |
void* operator new[](size_t, std::nothrow_t); |
(4) | |
void* operator new (size_t, void* ptr); |
(5) | |
void* operator new[](size_t, void* ptr); |
(6) | |
1-2)
ordnet angeforderte Anzahl von Bytes oder wirft std::bad_alloc im Fehlerfall
Original:
allocates requested number of bytes or throws std::bad_alloc on failure
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.
3-4)
ordnet angeforderte Anzahl von Bytes oder kehrt NULL im Fehlerfall
Original:
allocates requested number of bytes or returns NULL on failure
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.
5-6)
Renditen
ptr. Dies erlaubt es, ein Objekt in vom Benutzer bereitgestellten Speicherbereich zu konstruieren. Das Programm muss nicht definieren explizite Implementierungen für diese Funktionen .Original:
returns
ptr. This allows to construct an object in user-supplied memory area. The program must not define explicit implementations for these functions.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.
Object Initialisierung
Wenn array_n fehlt, wird einzelnes Objekt in der erworbenen Speicherbereich initialisiert, vorbei init_params als Parameter an den Konstruktor oder Aufrufen Standardkonstruktor, wenn sie nicht vorhanden sind .
Original:
If array_n is absent, single object is initialized in the acquired memory area, passing init_params as parameters to the constructor or invoking default constructor if they are not present.
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.
Wenn array_n vorhanden ist, wird eine Reihe von array_n Objekte initialisiert, vorbei init_params als Parameter an den Konstruktor für jedes Objekt oder den Aufruf Standardkonstruktor, wenn init_params nicht vorhanden sind .
Original:
If array_n is present, an array of array_n objects is initialized, passing init_params as parameters to the constructor of each object or invoking default constructor if init_params are not present.
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.