enumeration declaration
提供: cppreference.com
![]() |
このページは、Google 翻訳を使って英語版から機械翻訳されました。
翻訳には誤りや奇妙な言い回しがあるかもしれません。文章の上にポインタをおくと、元の文章が見れます。誤りを修正して翻訳を改善する手助けをしてください。翻訳についての説明は、ここをクリックしてください。 |
列挙型は、値が明示的にいくつかの名前付き定数( "列挙子")のいずれかに制限されている特殊タイプです。定数の値は、列挙体の基になる型として知られている整数型の値です。.
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) | (C++11およびそれ以降) | |||||||
enum struct name : type attr { enumerator = constexpr , enumerator = constexpr , ... None }
|
(3) | (C++11およびそれ以降) | |||||||
対象範囲外の列挙型を宣言します。各enumeratorは、囲んでいるスコープ内でアクセス可能になり、bool含む整数型に暗黙的に変換可能です。明示的に指定しない場合は、基になる型は、いくつかのintがconstexprに収まらない定数に評価されない限りintより広くすることはできませんすべての列挙値を表すことのできる整数型です
2-3) 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.
You can help to correct and verify the translation. Click here for instructions.
スコープの列挙型を宣言します。各enumeratorのみname::enumeratorとしてアクセスすることができます。整数型への変換はstatic_castで可能です。明示的に指定しない場合は、基になる型は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.
[編集] 説明
name | - | 型の名前は、この宣言によって宣言された。対象範囲外の列挙は、それが唯一の列挙定数などの名前が、新しい型を導入する場合には、無名のかもしれません
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) | - | 列挙体の基になる型として使用される任意の整数型(任意のCV-資格は無視されます)、.
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) | - | フォーム
[[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 | - | この宣言によって導入されたゼロ個以上の列挙子。列挙子の名前は定数が期待されてどこでも使用できます
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 | - | 列挙子に割り当てられる値に評価される任意の定数式。それが省略された場合は、値は、前の列挙プラス1の値です。最初の列挙子で省略した場合、値は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 |
[編集] 例
このコードを実行します
#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'; }
出力:
red = 0 blue = 21 a = l f = 3