Espaços nominais
Variantes
Acções

aggregate initialization

Da cppreference.com
< cpp‎ | language

 
 
Linguagem C++
Tópicos gerais
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.
Controle de fluxo
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.
Declarações execução condicional
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.
Instruções de iteração
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.
Ir declarações
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.
Funções
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
declaração da função
lambda declaração da função
modelo de função
linha especificador
especificações de exceção(obsoleta)
noexcept especificador(C++11)
Exceções
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.
Tipos
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)
Especificadores
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 especificadores
armazenamento duração especificadores
constexpr especificador(C++11)
auto especificador(C++11)
alignas especificador(C++11)
Inicialização
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Literais
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Expressões
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
representações alternativas
Utilitários
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Tipos
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 de alias declaração(C++11)
atributos(C++11)
Conversões
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
conversões implícitas
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
Elenco C-estilo e funcional
Alocação de memória
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.
Classe propriedades específicas de função
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.
Funções membro especiais
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.
Modelos
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
modelo de classe
modelo de função
especialização de modelo
pacotes de parâmetros(C++11)
Diversos
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Assembly embutido
 
Inicializa um agregado de braced-init-lista
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.

Índice

[editar]Sintaxe

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

[editar]Explicação

Inicialização agregada é uma forma de lista de inicialização, que inicializa agregados'
Original:
Aggregate initialization is a form of lista de inicialização, 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.
Um agregado é um objecto do tipo que é um dos seguintes procedimentos
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 de matriz
    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 de classe (geralmente, struct ou union), que possui
    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.
  • não membros privados ou protegidos
    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.
  • não fornecido pelo usuário construtores
    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.
  • sem classes 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.
  • sem funções de membro virtual
    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.
  • não inicializadores cinta-ou-iguais para membros não-estáticos
    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.
Os efeitos da inicialização agregada são:
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.
  • Cada elemento da matriz ou não-estático membro da classe, por ordem de índice de matriz / aparência na definição da classe, é cópia inicializado da cláusula correspondente da lista de inicializador.
    Original:
    Each array element or non-static class member, in order of array subscript/appearance in the class definition, is cópia inicializado 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 a cláusula é uma expressão inicializador, as conversões implícitas são permitidas, exceto (desde C++11) se eles estão estreitando (como em lista de inicialização).
    Original:
    If the initializer clause is an expression, implicit conversions are allowed, except (desde C++11) if they are narrowing (as in lista de inicialização).
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • Se a cláusula é um inicializador aninhada preparou-init-lista, o membro da classe correspondente é em si um agregado: inicialização agregada é recursivo.
    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 o objeto é um array de tamanho desconhecido, ea lista de inicializador fornecido cinta-fechado tem n cláusulas, o tamanho da matriz é 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.
  • Membros de dados estáticos e anônimos campos de bit são ignorados durante a inicialização do agregado.
    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 o número de cláusulas inicializador excede o número de membros para inicializar, o programa é mal-formado (erro de compilador)
    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 o número de cláusulas inicializador é menor que o número de membros, os membros restantes são inicializados por listas vazias, que realiza valor de inicialização. Se um membro de um tipo de referência é um desses membros restantes, o programa é mal formado (referências não podem ser de valor inicializado)
    Original:
    If the number of initializer clauses is less than the number of members, the remaining members are initialized by empty lists, which performs valor de inicialização. 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 a inicialização agregado utiliza a forma com o sinal de igual (T a ={args..}), as cintas em torno das listas de inicializador aninhados podem ser omitidos (omitido), caso em que, como cláusulas inicializador quantas forem necessárias são usados ​​para inicializar cada membro ou elemento do correspondente subaggregate, e as cláusulas inicializador subseqüentes são usados ​​para inicializar os seguintes membros do objeto. No entanto, se o objeto tem um sub-conjunto sem membros (uma estrutura vazia, ou uma estrutura segurando apenas membros estáticos), elisão cinta não é permitido, e uma lista vazia {} aninhada deve ser usado.
    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 um sindicato é inicializado pela inicialização agregado, apenas nos primeiros membros não-estáticos de dados é inicializado.
    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.

[editar]Notas

Até C + +11, conversões de estreitamento foram autorizados em inicialização agregada, mas eles não são mais permitidas.
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.
Até C + +11, inicialização agregada não poderia ser utilizado em uma lista de inicializador construtor devido a restrições de sintaxe.
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.

[editar]Exemplo

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


[editar]Veja também

close