enumeration declaration
De cppreference.com
[] |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
<metanoindex/>
Une numration est un type distinct dont la valeur est limite l'une des nombreuses constantes explicitement nomms ("recenseurs"). Les valeurs des constantes sont des valeurs d'un type intgral connu sous le type sous-jacent de l'numration .
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.
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) | (depuis C++11) | |||||||
enum struct name : type attr { enumerator = constexpr , enumerator = constexpr , ... None}
|
(3) | (depuis C++11) | |||||||
1)
dclare un type d'numration sans porte. Chaque enumerator devient accessible dans la porte, et est implicitement convertible en type intgral, y compris
bool. S'il n'est pas explicitement spcifi, le type sous-jacent est un type intgral capable de reprsenter toutes les valeurs d'numrateur, qui ne peuvent pas tre plus large que int moins que quelque constexpr value une constante qui ne rentre pas dans une intOriginal:
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 intThe 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.
2-3)
dclare un type d'numration porte. Chaque enumerator ne peut tre consulte que name::enumerator. Conversion de types intgraux est possible avec static_cast. S'il n'est pas explicitement spcifi, le type sous-jacent est
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.
You can help to correct and verify the translation. Click here for instructions.
Explication
| name | - | le nom du type dclar par cette dclaration. Une numration sans porte peut tre anonyme, auquel cas il ne prsente que des noms recenseurs comme des constantes, mais aucun nouveau type
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) | - | option type intgral (toute cv-qualification est ignor), utilis comme type sous-jacent de l'numration .
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) | - | zro ou plus spcifiques l'implmentation des attributs de la forme
[[attribute]] 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 | - | zro ou plusieurs agents recenseurs qui sont introduites par cette dclaration. Les noms des recenseurs peuvent tre utiliss partout constantes sont attendus
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 | - | facultative expression constante qui correspond la valeur attribuer l'agent recenseur. Si elle est omise, la valeur est la valeur de l'numrateur prcdent, plus
1. Si omis pour le premier recenseur, la valeur est 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. |
| This section is incomplete |
Exemple
#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';
}
Rsultat :
red = 0 blue = 21
a = l
f = 3