aggregate initialization
Da cppreference.com.
![]() | Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate. La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
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.
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.
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.
You can help to correct and verify the translation. Click here for instructions.
- tipo matriceOriginal:array typeThe 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 haOriginal: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.
- non membri privati o protettiOriginal: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. - non fornito dall'utente costruttoriOriginal: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. - no classi di baseOriginal:no base classesThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - non funzioni membro virtualiOriginal: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. - non inizializzatori coppia-o-pari membri non staticiOriginal: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.
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.
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 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.
- 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.
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.
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 }