[英]C++ Error: Too Many Initializer Values
I'm having a weird error with my arrays. 我的数组出现奇怪的错误。 I have declared them like so:
我已经这样声明了它们:
void Interface::setup(){
char pitchPlayers[9][26] = {
{ 201, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 187 }, //1
{ 186, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 186 }, //2
{ 186, ' ', ' ', ' ', ' ', ' ', ' ', 001, '1', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', 001, ' ', ' ', ' ', ' ', ' ', ' ', 186 }, //3
{ 186, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 186 }, //4
{ 186, ' ', 001, ' ', ' ', ' ', ' ', 001, '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '2', 001, ' ', ' ', ' ', ' ', 001, ' ', 186 }, //5
{ 186, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 186 }, //6
{ 186, ' ', ' ', ' ', ' ', ' ', ' ', 001, '3', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '3', 001, ' ', ' ', ' ', ' ', ' ', ' ', 186 }, //7
{ 186, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 186 }, //8
{ 200, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 188 }, //9
};
char dice[9][9] = {
{ 201, 205, 205, 205, 205, 205, 205, 205, 187 }, //1
{ 186, ' ', ' ', ' ', ' ', ' ', ' ', ' ', 186 }, //2
{ 186, ' ', 254, ' ', ' ', ' ', ' ', ' ', 186 }, //3
{ 186, ' ', ' ', ' ', ' ', ' ', ' ', ' ', 186 }, //4
{ 186, ' ', ' ', ' ', 254, ' ', ' ', ' ', 186 }, //5
{ 186, ' ', ' ', ' ', ' ', ' ', ' ', ' ', 186 }, //6
{ 186, ' ', ' ', ' ', ' ', ' ', 254, ' ', 186 }, //7
{ 186, ' ', ' ', ' ', ' ', ' ', ' ', ' ', 186 }, //8
{ 200, 205, 205, 205, 205, 205, 205, 205, 188 }, //9
};
}
Then I have the too many initializer values error on the 2nd row of the array when I want to change the contents of my array like so: 然后,当我想像这样更改数组的内容时,在数组的第二行上出现了太多的初始化值错误:
if (numberOfPlayers == 3) {
pitchPlayers[9][26] = {
{ 201, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 187 }, //1
{ 186, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 186 }, //2 - this line
{ 186, ' ', ' ', ' ', ' ', ' ', ' ', 001, '1', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', 001, ' ', ' ', ' ', ' ', ' ', ' ', 186 }, //3
{ 186, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 186 }, //4
{ 186, ' ', 001, ' ', ' ', ' ', ' ', 001, '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '2', 001, ' ', ' ', ' ', ' ', 001, ' ', 186 }, //5
{ 186, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 186 }, //6
{ 186, ' ', ' ', ' ', ' ', ' ', ' ', 001, '3', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '3', 001, ' ', ' ', ' ', ' ', ' ', ' ', 186 }, //7
{ 186, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 186 }, //8
{ 200, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 188 }, //9
};
for (int x = 0; x < 9; x++) {
for (int y = 0; y < 26; y++) {
cout << pitchPlayers[x][y];// cout << "X";
}
cout << endl;
}
cout << endl;
}
I have declared them properly in my header files and such. 我已经在头文件等中正确声明了它们。 I can't find what the problem would be.
我找不到问题所在。 I'm fairly new to C++ so it is probably a rookie error somewhere.
我对C ++相当陌生,因此它可能是某个地方的菜鸟错误。
Besides changing the scope of pitchPlayers
as was written in the comments, regarding changing the entire array after the declaration : You can delclare another initialized array called for example pitchPlayersFor3
. 除了更改注释中所写的
pitchPlayers
范围之外,还涉及在声明之后更改整个数组:您可以取消声明另一个初始化的数组,例如pitchPlayersFor3
。 Preferably declare it static
and const
. 最好将其声明为
static
和const
。 Then you can use memmove
to copy from pitchPlayersFor3
to pitchPlayers
. 然后,您可以使用
memmove
从pitchPlayersFor3
复制到pitchPlayers
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.