另一个:“太多初始化器”和“太多初始化器”。错误。 [英] Yet another: "Too many initializers" error.
问题描述
我的眼睛看起来很好。
生成错误C2078:初始化程序太多VS2008
< pre lang =c ++> static DWORD 2DArray [ 5 ] [ 4 ] =
{
{ 0 , 1 },{ 1 , 4 },{ 2 , 5 },{ 3 , 6 },{ 4 , 25 },
{ 0 , 2 },{ 1 , 9 },{ 2 , 10 },{ 3 , 11 },{ 4 , 26 },
{ 0 , 3 },{ 1 , 13 },{ 2 , 14 },{ 3 , 15 },{ 4 , 23 },
{< span class =code-digit> 0 , 4 },{ 1 ,< span class =code-digit> 17 },{ 2 , 18 }, { 3 , 19 },{ 4 , 22 }
};
:Ron
那是因为初始化程序太多了:P
你是指定数组为5x4,但你有初始值设定项20x2
要么使用静态DWORD 2DArray [20] [2] =
或更改初始化程序如下:
静态 DWORD 2DArray [ 5 ] [ 4 ] =
{
{ 0 , 1 , 2 , 3 }
{ 1 , 1 , 2 , 3 }
{ 2 ,< span class =code-digit> 1 , 2 , 3 }
{ 3 , 1 , 2 , 3 }
{ 4 , 1 , 2 , 3 }
}
编辑:也许你的意思是:
静态 DWORD 3DArray [ 4 ] [ 5 ] [ 2 ] =
{ // 有4 x 2DArray [5] [2]
{ // 有5 x Array [2]
{ 0 , 1 }, // 这是一个int [2]
{ 1 , 4 },
{ 2 , 5 },
{ 3 , 6 },
{ 4 , 25 }
},
{
{ 0 , 2 },{ 1 , 9 },{ 2 , 10 },{ 3 , 11 },{ 4 , 26 }
},
{
{ 0 , 3 },{ 1 , 13 },{ 2 , 14 },{ 3 , 15 },{ 4 , 23 }
},
{
{ 0 , 4 },{ 1 , 17 },{ 2 , 18 },{ 3 , 19 },{ 4 , 22 }
}
}
你不需要第一个数字,如果这些是与索引相关的真实数字。
我建议:
静态 DWORD 3DArray [ 4 ] [ 5 ] =
{ // 有4 x 2DArray [5]
{ // 有5 x int
1 , 4 , 5 , 6 , 25 } ,
{ 2 , 9 , 10 , 11 , 26 },
{ 3 , 13 , 14 , 15 , 23 },
{ 4 , 17 , 18 , 19 , 22 }
}
不要放弃,欺骗编译器:
struct DWORD
{
int x, Ÿ;
};
静态 DWORD数组[ 5 ] [ 4 ] =
{
{{ 0 , 1 }, { 1 , 4 },{ 2 , 5 },{ 3 , 6 },},
{{ 4 , 25 },{ 0 , 2 },{ 1 , 9 },{ 2 , 10 },},
{{ 3 , 11 },{ 4 , 26 },{ 0 , 3 },{1 , 13 },},
{{ 2 , 14 },{ 3 , 15 },{ 4 , 23 },{ 0 , 4 },},
{{ 1 ,< span class =code-digit> 17 },{ 2 , 18 }, { 3 , 19 },{ 4 , 22 },},
};
: OMG:
Looks ok to my eyes.
Generates error C2078: too many initializers VS2008
static DWORD 2DArray[5][4] =
{
{ 0 , 1 }, { 1 , 4 }, { 2 , 5 }, { 3 , 6 }, { 4 , 25 },
{ 0 , 2 }, { 1 , 9 }, { 2 , 10}, { 3 , 11}, { 4 , 26 },
{ 0 , 3 }, { 1 , 13}, { 2 , 14}, { 3 , 15}, { 4 , 23 },
{ 0 , 4 }, { 1 , 17}, { 2 , 18}, { 3 , 19}, { 4 , 22 }
};
:Ron
That's because there are too many initializers :P
You are specifying the array as 5x4, yet you have initializers 20x2
Either usestatic DWORD 2DArray[20][2] =
or change the initializer like so:
static DWORD 2DArray[5][4] = { { 0 , 1 , 2 , 3 } { 1 , 1 , 2 , 3 } { 2 , 1 , 2 , 3 } { 3 , 1 , 2 , 3 } { 4 , 1 , 2 , 3 } }
EDIT: Perhaps you meant:
static DWORD 3DArray[4][5][2] = {// there are 4 x 2DArray[5][2] {// there are 5 x Array[2] { 0 , 1 }, // this is an int[2] { 1 , 4 }, { 2 , 5 }, { 3 , 6 }, { 4 , 25 } }, { { 0 , 2 }, { 1 , 9 }, { 2 , 10}, { 3 , 11}, { 4 , 26 } }, { { 0 , 3 }, { 1 , 13}, { 2 , 14}, { 3 , 15}, { 4 , 23 } }, { { 0 , 4 }, { 1 , 17}, { 2 , 18}, { 3 , 19}, { 4 , 22 } } }
You don't need the first digit if these are the real numbers as they relate to the index anyway.
I would suggest:
static DWORD 3DArray[4][5] = {// there are 4 x 2DArray[5] {// there are 5 x int 1, 4, 5, 6, 25 }, { 2 , 9 , 10 , 11 , 26 }, { 3 , 13 , 14 , 15 , 23 }, { 4 , 17 , 18 , 19 , 22 } }
Don't give up, cheat on the compiler:
struct DWORD { int x,y; }; static DWORD Array[5][4] = { { { 0 , 1}, { 1 , 4}, { 2 , 5}, { 3 , 6}, }, { { 4 , 25}, { 0 , 2}, { 1 , 9}, { 2 , 10}, }, { { 3 , 11}, { 4 , 26}, { 0 , 3}, { 1 , 13}, }, { { 2 , 14}, { 3 , 15}, { 4 , 23}, { 0 , 4}, }, { { 1 , 17}, { 2 , 18}, { 3 , 19}, { 4 , 22}, }, };
:omg:
这篇关于另一个:“太多初始化器”和“太多初始化器”。错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!