aggregate initialization

Da cppreference.com.
< cpp‎ | language

 
 
Linguaggio C + +
Temi generali
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.
Controllo del flusso
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.
Dichiarazioni esecuzione condizionale
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.
Iterazione dichiarazioni
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.
Vai dichiarazioni
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.
Funzioni
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
dichiarazione di funzione
lambda funzione dichiarazione
funzione di modello
specificatore inline
eccezioni specifiche(deprecato)
noexcept specificatore(C++11)
Eccezioni
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Spazi dei nomi
Original:
Namespaces
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Tipi
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 specificatori
Durata di stoccaggio specificatori
constexpr specificatore(C++11)
specificatore auto(C++11)
alignas specificatore(C++11)
Inizializzazione
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Letterali
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Espressioni
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
rappresentazioni alternative
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.
Tipi
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
Tipo alias dichiarazione(C++11)
attributi(C++11)
Lancia
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
conversioni implicite
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
Fusione C-stile e funzionale
Occupazione della memoria
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.
Classi
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Specifiche per una classe di funzioni proprietà
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.
Funzioni membro speciali
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.
Modelli
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
classe template
funzione di modello
modello di specializzazione
parametri confezioni(C++11)
Varie
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Montaggio in linea
 
Inizializza un aggregato da rinforzato-init-list
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.

Indice

[modifica]Sintassi

Tobject= {arg1, arg2, ...}; (1)
Tobject {arg1, arg2, ...}; (2) (dal C++11)

[modifica]Spiegazione

Inizializzazione aggregata è una forma di list-inizializzazione, che inizializza aggregati'
Original:
Aggregate initialization is a form of list-inizializzazione, 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.
Un aggregato è un oggetto del tipo che è uno dei seguenti
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.
  • tipo matrice
    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.
  • tipo di classe (in genere, struct o union), che ha
    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.
  • non membri privati ​​o protetti
    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.
  • non fornito dall'utente costruttori
    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.
  • no classi di base
    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.
  • non funzioni membro virtuali
    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.
  • non inizializzatori coppia-o-pari membri non statici
    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.
Gli effetti di inizializzazione aggregato sono:
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.
  • Ogni elemento di un array o di membro non statico di classe, in ordine di indice di matrice / aspetto nella definizione della classe, è copia-inizializzato dalla clausola corrispondente della lista di inizializzazione.
    Original:
    Each array element or non-static class member, in order of array subscript/appearance in the class definition, is copia-inizializzato 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.
  • Se la clausola inizializzatore è un'espressione, le conversioni implicite sono consentiti, tranne (dal C++11) se stanno diminuendo (come in list-inizializzazione).
    Original:
    If the initializer clause is an expression, implicit conversions are allowed, except (dal C++11) if they are narrowing (as in list-inizializzazione).
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • Se la clausola è un inizializzatore nidificato rinforzato-init-list, il membro della classe corrispondente è di per sé un aggregato: inizializzazione aggregata è ricorsiva.
    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.
  • Se l'oggetto è una matrice di dimensione sconosciuta, e la coppia fornita chiuso in lista di inizializzazione ha n clausole, la dimensione della matrice è 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.
  • Membri dati statici e anonimi bit-field vengono saltati durante l'inizializzazione aggregata.
    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.
  • Se il numero di clausole di inizializzazione è superiore al numero dei membri per l'inizializzazione, il programma è mal formato (errore del compilatore)
    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.
  • Se il numero di clausole di inizializzazione è inferiore al numero dei membri, i membri rimanenti vengono inizializzati da elenchi vuoti, che svolge valore di inizializzazione. Se un membro di un tipo di riferimento è uno di questi componenti rimanenti, il programma è malformati (riferimenti non può essere inizializzato valore)
    Original:
    If the number of initializer clauses is less than the number of members, the remaining members are initialized by empty lists, which performs valore di inizializzazione. 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.
  • Se l'inizializzazione aggregata usa la forma con il segno di uguale (T a ={args..}), le parentesi intorno alle liste di inizializzazione nidificati possono essere eliso (omissis), in questo caso, le clausole di inizializzazione quante sono necessarie vengono utilizzate per inizializzare ogni membro o elemento del corrispondente subaggregate, e le clausole di inizializzazione successivi vengono utilizzati per inizializzare i seguenti membri dell'oggetto. Tuttavia, se l'oggetto ha un sub-aggregato, senza tutti i membri (una struttura vuota, o una struttura che tiene solo membri statici), elisione tutore non è consentito, e un vuoto {} lista annidata deve essere utilizzato.
    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.
  • Quando un sindacato viene inizializzata dal inizializzazione aggregata, solo i primi suoi membri non statici di dati viene inizializzato.
    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.

[modifica]Note

Fino al C + +11, conversioni di restrizione sono stati ammessi in inizializzazioni di aggregazione, ma non sono più ammessi.
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.
Fino al C + +11, l'inizializzazione aggregata non può essere utilizzato in una lista di inizializzazione del costruttore a causa di restrizioni di sintassi.
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.

[modifica]Esempio

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


[modifica]Vedi anche

close