Espaços nominais
Variantes
Acções

enumeration declaration

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.
tipos fundamentais
tipos de compostos
tipos de enumeração
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
 
Uma enumeração é um tipo distinto cujo valor é restrito a uma das várias constantes explicitamente nomeados ("entrevistadores"). Os valores das constantes são valores de um tipo conhecido como parte integrante do tipo subjacente da enumeração.
Original:
An enumeration is a distinct type whose value is restricted to one of several explicitly named constants ("enumerators"). The values of the constants are values of an integral type known as the underlying type of the enumeration.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
enum name : type attr { enumerator = constexpr , enumerator = constexpr , ... None} (1)
enum class name : type attr { enumerator = constexpr , enumerator = constexpr , ... None} (2) (desde C++11)
enum struct name : type attr { enumerator = constexpr , enumerator = constexpr , ... None} (3) (desde C++11)
1)
declara um tipo de enumeração sem escopo. Cada enumerator torna-se acessível no escopo limitado, e é implicitamente conversível para o tipo integral, incluindo bool. Se não for especificado explicitamente, o tipo subjacente é um tipo integral, capaz de representar todos os valores de enumerador, que não pode ser maior do que a menos que algum int constexpr avalia a uma constante que não se encaixa em um int
Original:
declares an unscoped enumeration type. Each enumerator becomes accessible in the enclosing scope, and is implicitly-convertible to integral type, including bool. If not explicitly specified, the underlying type is an integral type capable of representing all enumerator values, which cannot be wider than int unless some constexpr evaluates to a constant that does not fit in an int
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2-3)
declara um tipo de enumeração escopo. Cada enumerator só pode ser acessado como name::enumerator. Conversão para tipos integrais é possível com static_cast. Se não for especificado explicitamente, o tipo subjacente é int.
Original:
declares a scoped enumeration type. Each enumerator can only be accessed as name::enumerator. Conversion to integral types is possible with static_cast. If not explicitly specified, the underlying type is int.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Explicação

name -
o nome do tipo declarado por esta declaração. Uma enumeração sem escopo pode ser sem nome, caso em que só introduz nomes enumerador como constantes, mas nenhum novo tipo
Original:
the name of the type declared by this declaration. An unscoped enumeration may be nameless, in which case it only introduces enumerator names as constants, but no new type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
type(C++11) -
tipo integral opcional (qualquer cv-qualificação é ignorado), usado como o tipo subjacente da enumeração .
Original:
optional integral type (any cv-qualification is ignored), used as the underlying type of the enumeration.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
attr(C++11) -
zero ou uma aplicação mais atributos específicos do [[attribute]] formulário
Original:
zero or more implementation-specific attributes of the form [[attribute]]
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
enumerator -
zero ou mais entrevistadores que são introduzidas por esta declaração. Os nomes dos inquiridores pode ser usado em qualquer lugar as constantes são esperados
Original:
zero or more enumerators which are introduced by this declaration. The names of the enumerators may be used anywhere constants are expected
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
constexpr -
expressão constante opcional que avalia o valor a ser atribuído para o enumerador. Se ele for omitido, o valor é o valor do enumerador anterior mais 1. Se omitido para o primeiro enumerador, o valor é 0
Original:
optional constant expression which evaluates to the value to be assigned to the enumerator. If it is omitted, the value is the value of the previous enumerator plus 1. If omitted for the first enumerator, the value is 0
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 <iostream>
// color may be red (value 0), yellow (value 1), green (value 20), or blue (value 21)
enum color {
    red,
    yellow,
    green = 20,
    blue
};
// altitude may be altitude::high or altitude::low
enum class altitude : char { 
     high='h',
     low='l', // C++11 allows the extra comma
}; 
// the constant d is 0, the constant e is 1, the constant f is 3
enum { d, e, f=e+2 };
int main()
{
    color col = red;
    altitude a;
    a = altitude::low;
 
    std::cout << "red = " << col << " blue = " << blue << '\n'
              << "a = " << static_cast<char>(a) << '\n'
              << "f = " << f << '\n';
}

Saída:

red = 0 blue = 21
a = l
f = 3