Namensräume
Varianten

aggregate initialization

Aus cppreference.com
< cpp‎ | language

 
 
Sprache C++
Allgemeine Themen
Original:
General topics
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Flusskontrolle
Original:
Flow control
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Bedingte Ausführung Aussagen
Original:
Conditional execution statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Iterationsanweisungen
Original:
Iteration statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Gehe Aussagen
Original:
Jump statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Funktionen
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Funktion Erklärung
Lambda-Funktion Erklärung
Funktions-Template
inline-Spezifizierer
Exception-Spezifikationen(veraltet)
noexcept Spezifizierer(C++11)
Ausnahmen
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Namespaces
Original:
Namespaces
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Types
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
decltype specifier(C++11)
Specifiers
Original:
Specifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
cv Planer
Lagerdauer Planer
constexpr Spezifizierer(C++11)
auto Spezifizierer(C++11)
alignas Spezifizierer(C++11)
Initialisierung
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Literale
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Expressions
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
alternative Darstellungen
Utilities
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Types
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
typedef declaration
Typ Aliasdeklaration(C++11)
Attribute(C++11)
Wirft
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
impliziten Konvertierungen
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
C-Stil und funktionale Besetzung
Speicherzuweisung
Original:
Memory allocation
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Classes
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Class-spezifische Funktion Eigenschaften
Original:
Class-specific function properties
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Besondere Member-Funktionen
Original:
Special member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Templates
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Klassen-Template
Funktions-Template
Template-Spezialisierung
Parameter Packs(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.
Inline Montage
 
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.

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.
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.
  • Array-Typ
    Original:
    array type
    The 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 das
    Original:
    class type (typically, struct or union), that has
    The 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 Mitglieder
    Original:
    no private or protected members
    The 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 gestellt
    Original:
    no user-provided constructors
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • keine Basisklassen
    Original:
    no base classes
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • keine virtuellen Member-Funktionen
    Original:
    no virtual member functions
    The 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 Member
    Original:
    no brace-or-equal initializers for non-static members
    The 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.
  • 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 Arrays n
    Original:
    If the object is an array of unknown size, and the supplied brace-enclosed initializer list has n clauses, the size of the array is n
    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.
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.

[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   }


[Bearbeiten]Siehe auch

close