aggregate initialization
提供: cppreference.com
![]() | このページは、Google 翻訳を使って英語版から機械翻訳されました。 翻訳には誤りや奇妙な言い回しがあるかもしれません。文章の上にポインタをおくと、元の文章が見れます。誤りを修正して翻訳を改善する手助けをしてください。翻訳についての説明は、ここをクリックしてください。 |
ブレース-initはリストから集計を初期化します
Original:
Initializes an aggregate from braced-init-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.
目次 |
[編集]構文
Tobject= { arg1, arg2, ...}; | (1) | ||||||||
Tobject { arg1, arg2, ...}; | (2) | (C++11およびそれ以降) | |||||||
[編集]説明
集約の初期化は、'集合体を初期化リスト初期化のフォームです
Original:
Aggregate initialization is a form of リスト初期化, which initializes aggregates
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:
An aggregate is an object of the type that is one of the following
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:array typeThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - クラス型(典型的には、structまたはunion)、それは持っていますOriginal:class type (typically, struct or union), that hasThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- ノープライベートまたはプロテクトメンバーOriginal:no private or protected membersThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - は、ユーザーが提供するコンストラクタがありませんOriginal:no user-provided constructorsThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - ない基底クラスはありませんOriginal:no base classesThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - ノー仮想メンバ関数Original:no virtual member functionsThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - 非静的メンバに対してブレースか等しい初期ませんOriginal:no brace-or-equal initializers for non-static membersThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
集約の初期化の効果は、次のとおりです
Original:
The effects of aggregate initialization are:
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:Each array element or non-static class member, in order of array subscript/appearance in the class definition, is コピー初期化 from the corresponding clause of 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.
- 初期化句が式であれば、彼らは((C++11およびそれ以降)のように)狭くしている場合は、暗黙的な変換がリスト初期化除いて、許可されてい.Original:If the initializer clause is an expression, implicit conversions are allowed, except (C++11およびそれ以降) if they are narrowing (as in リスト初期化).The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- 初期化子の句は、ネストされたブレース-INIT-リストである場合、対応するクラスのメンバーは、それ自体である集計:集計初期化は再帰的です.Original:If the initializer clause is a nested braced-init-list, the corresponding class member is itself an aggregate: aggregate initialization is recursive.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- オブジェクトが未知のサイズの配列であり、供給中括弧で囲まれた初期化子リストは
n
句を持っている場合は、配列のサイズはn
ですOriginal:If the object is an array of unknown size, and the supplied brace-enclosed initializer list hasn
clauses, the size of the array isn
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- 静的データメンバと匿名のビットフィールドは、集約の初期化中にスキップされます.Original:Static data members and anonymous bit-fields are skipped during aggregate initialization.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- 初期化子の句の数は初期化するメンバーの数を超えている場合、プログラムは(コンパイラエラー)不適格ですOriginal:If the number of initializer clauses exceeds the number of members to initialize, the program is ill-formed (compiler error)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- 初期化子の句の数はメンバーの数より少ない場合、残りのメンバーは値初期化を行い、空のリストで初期化されます。参照型のメンバは、これらの残りのメンバーの一人である場合、プログラムは不適格である(参照は値初期化することはできません)Original:If the number of initializer clauses is less than the number of members, the remaining members are initialized by empty lists, which performs 値初期化. If a member of a reference type is one of these remaining members, the program is ill-formed (references cannot be value-initialized)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- 集約の初期化は、等号(T a ={args..})でフォームを使用する場合は、ネストされた初期化子リストを囲む中括弧は、その場合には、必要な数の初期化句が対応のすべてのメンバーまたは要素を初期化するために使用され、(中略)削除されるかもしれませんsubaggregate、その後の初期化子の句は、オブジェクトの次のメンバを初期化するために使用されます。オブジェクトがどのメンバー(空の構造体、または静的メンバのみを保持する構造体)をせずにサブ集合を持っている場合は、中括弧省略は許されず、空のネストされたリスト
{}
を使用しなければなりません.Original:If the aggregate initialization uses the form with the equal sign (T a ={args..}), the braces around the nested initializer lists may be elided (omitted), in which case, as many initializer clauses as necessary are used to initialize every member or element of the corresponding subaggregate, and the subsequent initializer clauses are used to initialize the following members of the object. However, if the object has a sub-aggregate without any members (an empty struct, or a struct holding only static members), brace elision is not allowed, and an empty nested list{}
must be used.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- 組合が集約の初期化で初期化される時にのみ、その最初の非静的データメンバが初期化され.Original:When a union is initialized by aggregate initialization, only its first non-static data members is initialized.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
[編集]ノート
℃まで+ 11、縮小変換は、集約の初期化では許可されていましたが、これは許可されなくなりました.
Original:
Until C++11, narrowing conversions were permitted in aggregate initialization, but they are no longer allowed.
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.
C + + 11まで、集約の初期化は、構文上の制限により、コンストラクタ初期化子リストでは使用できませんでした.
Original:
Until C++11, aggregate initialization could not be used in a constructor initializer list due to syntax restrictions.
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.
[編集]例
#include <string>#include <array>struct S {int x;struct Foo {int i;int j;int a[3];} b;}; union U {int a;constchar* b;};int main(){ S s1 ={1, {2, 3, {4, 5, 6}}}; S s2 ={1, 2, 3, 4, 5, 6};// same, but with brace elision S s3{1, {2, 3, {4, 5, 6}}};// same, using direct-list-initialization syntax// S s4{1, 2, 3, 4, 5, 6}; // error: brace-elision only allowed with equals sign int ar[]={1,2,3};// ar is int[3]// char cr[3] = {'a', 'b', 'c', 'd'}; // too many initializer clauseschar cr[3]={'a'};// array initialized as {'a', '\0', '\0'} int ar2d1[2][2]={{1, 2}, {3, 4}};// fully-braced 2D array: {1, 2}// {3, 4}int ar2d2[2][2]={1, 2, 3, 4};// brace elision: {1, 2}// {3, 4}int ar2d3[2][2]={{1}, {2}};// only first column: {1, 0}// {2, 0} std::array<int, 3> std_ar2{{1,2,3}};// std::array is an aggregatestd::array<int, 3> std_ar1 ={1, 2, 3};// brace-elision okay int ai[]={1, 2.0};// narrowing conversion from double to int:// error in C++11, okay in C++03 std::string ars[]={std::string("one"), // copy-initialization"two", // conversion, then copy-initialization{'t', 'h', 'r', 'e', 'e'}};// list-initialization U u1 ={1};// OK, first member of the union// U u2 = { 0, "asdf" }; // error: too many initializers for union// U u3 = { "asdf" }; // error: invalid conversion to int }