名前空間
変種
操作

enumeration declaration

提供: cppreference.com
< cpp‎ | language

 
 
C + +言語
一般的なトピック
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.
フロー制御
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.
条件付き実行文
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.
繰り返し文
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.
文をジャンプします
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.
機能します
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
関数の宣言
ラムダ関数の宣言
関数テンプレート
の歴史。インライン指定
例外仕様 (廃止予定)
noexcept指定子 (C++11)
例外
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
名前空間
Original:
Namespaces
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
タイプ
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)
指定子
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指定
貯蔵期間指定
constexprの指定子 (C++11)
自動指定 (C++11)
alignas指定子 (C++11)
初期化
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
リテラル
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
代替表現
ユーティリティ
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
タイプ
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
型の別名宣言 (C++11)
属性 (C++11)
キャストします
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
暗黙の型変換
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
Cスタイルキャストと機能
メモリの割り当て
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.
クラス
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
クラス固有の機能特性
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.
明示 (C++11)
静的
特殊なメンバ関数
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.
テンプレート
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
クラステンプレート
関数テンプレート
テンプレートの特殊化
パラメーターパック (C++11)
その他
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
インラインアセンブリ
 
列挙型は、値が明示的にいくつかの名前付き定数( "列挙子")のいずれかに制限されている特殊タイプです。定数の値は、列挙体の基になる型として知られている整数型の値です。.
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) (C++11およびそれ以降)
enum struct name : type attr { enumerator = constexpr , enumerator = constexpr , ... None} (3) (C++11およびそれ以降)
1)
対象範囲外の列挙型を宣言します。各enumeratorは、囲んでいるスコープ内でアクセス可能になり、bool含む整数型に暗黙的に変換可能です。明示的に指定しない場合は、基になる型は、いくつかのintconstexprに収まらない定数に評価されない限り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)
スコープの列挙型を宣言します。各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.

[編集] 説明

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.

[編集]

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

Output:

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