aggregate initialization
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. |
Initialisiert ein Aggregat aus braced-init-Liste
Original:
Initializes an aggregate from braced-init-list
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.
Inhaltsverzeichnis |
[Bearbeiten]Syntax
Tobject= { arg1, arg2, ...}; | (1) | ||||||||
Tobject { arg1, arg2, ...}; | (2) | (seit C++11) | |||||||
[Bearbeiten]Erklärung
Aggregat Initialisierung ist eine Form der list-Initialisierung, die Aggregate initialisiert'
Original:
Aggregate initialization is a form of list-Initialisierung, which initializes aggregates
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 Aggregat ist eine Aufgabe der Art, die eine der folgenden ist
Original:
An aggregate is an object of the type that is one of the following
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.
- Array-TypOriginal:array typeThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Klasse Typ (in der Regel struct oder union), hat dasOriginal:class type (typically, struct or union), that hasThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- keine private oder protected MitgliederOriginal:no private or protected membersThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - keine Konstruktoren Benutzer zur Verfügung gestelltOriginal:no user-provided constructorsThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - keine BasisklassenOriginal:no base classesThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - keine virtuellen Member-FunktionenOriginal:no virtual member functionsThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - keine Klammer-oder-gleich Initialisierungen für nicht-statische MemberOriginal:no brace-or-equal initializers for non-static membersThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Die Auswirkungen der gesamtwirtschaftlichen Initialisierung sind:
Original:
The effects of aggregate initialization are:
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.
- Jedes Array-Element oder nicht-statische Klassen-Member in der Reihenfolge der Array-Index / Auftritt in der Klasse Definition ist copy-initialisiert aus der entsprechenden Klausel der Initialisierungsliste .Original:Each array element or non-static class member, in order of array subscript/appearance in the class definition, is copy-initialisiert from the corresponding clause of the initializer list.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- Wenn die Initialisierung Klausel ist ein Ausdruck, sind implizite Konvertierungen erlaubt, außer (seit C++11) wenn sie verengt (wie in list-Initialisierung) werden .Original:If the initializer clause is an expression, implicit conversions are allowed, except (seit C++11) if they are narrowing (as in list-Initialisierung).The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- Wenn die Initialisierung Klausel ist eine verschachtelte verspannt-init-Liste, ist die entsprechende Klasse Element selbst ein Aggregat: Aggregat Initialisierung rekursive .Original:If the initializer clause is a nested braced-init-list, the corresponding class member is itself an aggregate: aggregate initialization is recursive.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- Wenn das Objekt ist ein Array von unbekannter Größe, und die mitgelieferte Klammer geschlossene Initialisierungsliste hat
n
Klauseln, ist die Größe des Arraysn
Original:If the object is an array of unknown size, and the supplied brace-enclosed initializer list hasn
clauses, the size of the array isn
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- Statische Daten-Member und anonyme Bit-Felder werden während der gesamten Initialisierung übersprungen .Original:Static data members and anonymous bit-fields are skipped during aggregate initialization.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- Wenn die Anzahl der Initialisierung Klauseln übersteigt die Zahl der Mitglieder zu initialisieren, ist das Programm mangelhafte (Compiler-Fehler)Original:If the number of initializer clauses exceeds the number of members to initialize, the program is ill-formed (compiler error)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- Wenn die Anzahl der Initialisierung Klauseln kleiner ist als die Zahl der Mitglieder, die restlichen Mitglieder durch leere Listen, die Value-Initialisierung führt initialisiert. Wenn ein Mitglied einer Referenz-Typ ist einer dieser übrigen Mitglieder ist das Programm falsch gebildete (Referenzen können nicht Wert initialisiert)Original:If the number of initializer clauses is less than the number of members, the remaining members are initialized by empty lists, which performs Value-Initialisierung. If a member of a reference type is one of these remaining members, the program is ill-formed (references cannot be value-initialized)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- Wenn das Aggregat Initialisierung verwendet das Formular mit dem Gleichheitszeichen (T a ={args..}) können die Klammern um den verschachtelten Initialisierer Listen elidiert (weggelassen werden), in diesem Fall, wie viele Initialisierer Klauseln wie nötig verwendet werden, um jedes Mitglied oder ein Element der entsprechenden initialisieren Teilaggregat, und die anschließende Initialisierung Klauseln verwendet werden, um die folgenden Mitglieder des Objekts zu initialisieren. Allerdings, wenn das Objekt eine sub-Aggregat ohne Mitglieder (eine leere Struktur oder eine Struktur hält nur statische Member) wird brace elision nicht erlaubt, und eine leere verschachtelte Liste
{}
verwendet werden .Original:If the aggregate initialization uses the form with the equal sign (T a ={args..}), the braces around the nested initializer lists may be elided (omitted), in which case, as many initializer clauses as necessary are used to initialize every member or element of the corresponding subaggregate, and the subsequent initializer clauses are used to initialize the following members of the object. However, if the object has a sub-aggregate without any members (an empty struct, or a struct holding only static members), brace elision is not allowed, and an empty nested list{}
must be used.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- Wenn eine Gewerkschaft von aggregierten Initialisierungsliste initialisiert wird, wird nur die erste nicht-statische Datenelemente initialisiert .Original:When a union is initialized by aggregate initialization, only its first non-static data members is initialized.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
[Bearbeiten]Notes
Bis C + +11, wurden einschränkende Konvertierungen in aggregierter Initialisierung zulässig, aber sie sind nicht mehr erlaubt .
Original:
Until C++11, narrowing conversions were permitted in aggregate initialization, but they are no longer allowed.
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.
Bis C + +11, konnte aggregierten Initialisierung nicht in einem Konstruktor Initialisierungsliste aufgrund Syntax Einschränkungen verwendet werden .
Original:
Until C++11, aggregate initialization could not be used in a constructor initializer list due to syntax restrictions.
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]Beispiel
#include <string>#include <array>struct S {int x;struct Foo {int i;int j;int a[3];} b;}; union U {int a;constchar* b;};int main(){ S s1 ={1, {2, 3, {4, 5, 6}}}; S s2 ={1, 2, 3, 4, 5, 6};// same, but with brace elision S s3{1, {2, 3, {4, 5, 6}}};// same, using direct-list-initialization syntax// S s4{1, 2, 3, 4, 5, 6}; // error: brace-elision only allowed with equals sign int ar[]={1,2,3};// ar is int[3]// char cr[3] = {'a', 'b', 'c', 'd'}; // too many initializer clauseschar cr[3]={'a'};// array initialized as {'a', '\0', '\0'} int ar2d1[2][2]={{1, 2}, {3, 4}};// fully-braced 2D array: {1, 2}// {3, 4}int ar2d2[2][2]={1, 2, 3, 4};// brace elision: {1, 2}// {3, 4}int ar2d3[2][2]={{1}, {2}};// only first column: {1, 0}// {2, 0} std::array<int, 3> std_ar2{{1,2,3}};// std::array is an aggregatestd::array<int, 3> std_ar1 ={1, 2, 3};// brace-elision okay int ai[]={1, 2.0};// narrowing conversion from double to int:// error in C++11, okay in C++03 std::string ars[]={std::string("one"), // copy-initialization"two", // conversion, then copy-initialization{'t', 'h', 'r', 'e', 'e'}};// list-initialization U u1 ={1};// OK, first member of the union// U u2 = { 0, "asdf" }; // error: too many initializers for union// U u3 = { "asdf" }; // error: invalid conversion to int }