Initializer list
提供: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. |
(はstd :: initializer_listと混同しないでください)
Original:
( Not to be confused with はstd :: initializer_list )
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.
彼らは、メンバーと祖先の初期化のために責任があるコンストラクタの一部です
Original:
They are the part of a constructor which is responsible for member and ancestor initialization
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.
[編集] 構文
constructor_signature : member_constructor_calls { constructor_body }
|
|||||||||
[編集] 説明
初期化子リストは、オブジェクトの初期化が必要な箇所ですが、基底クラスやメンバのコンストラクタが呼び出されている場所がある.
Original:
The initializer list is the place where initialization of the object should occur, there is where the constructors for base classes and members are called.
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.
宣言されているようなメンバーは、彼らは初期化子リストで表示されないように、同じ順序で初期化され.
Original:
Members are initialized in the same order as they are declared, not as they appear in 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.
You can help to correct and verify the translation. Click here for instructions.
コンストラクタのパラメータは、メンバーの一人、intializerリスト内部のコンストラクタ呼び出しで渡されて、その識別子の曖昧さと同じ名前を持つ場合は、このパラメータを(メンバーではありません)を選択する解決されています.
Original:
If a parameter in the constructor has the same name as one of the members, the ambiguity of that identifier being passed in a constructor call inside the intializer list is resolved choosing the parameter (and not the member).
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.
リスト内に存在しないメンバや基本クラスは、デフォルトで構成されるでしょう
Original:
Members or base classes not present in the list will be default constructed
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.
[編集] 例
struct Class : public Base { int x; int y; Class ( int x ) : Base ( 123 ), // initialize base class x ( x ), // x (member) is initialized with x (parameter) y ( 0 ) // y initialized to 0 {} // empty constructor body Class ( double a ) : y ( a+1 ), x ( y ) // x will be initialized before y, this means that its value here is undefined {} // No base class constructor in list, this is the same as calling Base() Class() try : Base ( 789 ), x ( 0 ), y ( 0 ) { // no exception } catch (...) { // exception occurred on initialization } };