struct S { int[5] x; } void main() { S s = S(); } The above code fails to compile with the following errors: Error: cannot implicitly convert expression (0) of type int to int[5] Error: cannot cast int to int[5] (Notice the lack of line numbers.) The "S s = S();" line works at global scope, or when preceded by const or static. The only way to circumvent this is to add an initializer for each array element: struct S { //int[5] x = 0; // what the compiler tries: doesn't work //int[5] x = []; // void[0], not int[5] //int[5] x = cast(int[5])[]; // non-constant expression //int[5] x = [0]; // int[1], not int[5] as above // this works, but is tedious for long arrays // (although it can be automated with templates) int[5] x = [0,0,0,0,0]; }
Fixed in 1.017.
Added to DStress as http://dstress.kuehne.cn/run/s/struct_initialization_12_A.d http://dstress.kuehne.cn/run/s/struct_initialization_12_B.d http://dstress.kuehne.cn/run/s/struct_initialization_12_C.d http://dstress.kuehne.cn/run/s/struct_initialization_12_D.d
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル