我有一个arduino项目,它使用二维数组来跟踪行/列信息。如果我尝试将行,列对分配给特定元素,则会出现错误:
expected primary-expression before '{' token
我可以毫无问题地分配单个值,但如果我尝试将第二个数组元素指定为整数对,则会出错。
example:
player[0][0] = 1;
player[0][1] = 2; //this works
//but . . .
player[0] = {1,2}; //doesn't work
//here is more specific code from the project
// …. a bunch of code here declaring various global variables
int players[6][2]; //two dimensional array with 6 players each with a 2 value array (column and row)
int score1; //player 1 score
int score2; //player2 score
//code here for setup/loop/etc.. Code calls the setPlayerPositions() function
void setPlayerPositions()
{
players[0] = {2,1}; //set the position of the ball (player[0]) to row 2, column 1
players[1] = {1,4}; //set other player positions . . .
players[2] = {2,4};
players[3] = {3,4};
players[4] = {2,6};
players[5] = {2,9};
}
答案 0 :(得分:2)
我已经把这个问题从桌子上砸了几次。
不幸的是,初始化数组时只能使用大括号表示法。初始化后,您必须单独处理每个数组元素。
参考:Arduino Cookbook ...... http://books.google.co.uk/books?id=nxxKNCYXRIwC&lpg=PA31&ots=dH_fWczOAp&pg=PA31#v=onepage