我在这里为C99做错了什么:
struct chess {
struct coordinate {
char piece;
int alive;
} pos[3];
}table[3] =
{
{
{'Q', (int)1},{'Q', (int)1},{'Q', (int)1},
{'B', (int)1},{'B', (int)1},{'B', (int)1},
{'K', (int)1},{'K', (int)1},{'K', (int)1},
}
};
它给出了错误:
error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘=’ token
我希望能够像在一个结构中拥有一个结构那样来访问数据:
table[row].pos[column].piece
table[row].pos[column].alive
我尝试了几种组合,但似乎没有一种适用于这种情况。在此之前,我已经完成了先前的结构硬编码初始化,但是这次还没有完成结构中的结构。
有什么建议么?
struct chess {
struct coordinate {
char piece;
int alive;
} pos[3];
} table[3] =
{
{
.pos = {{ .piece = 'Q', .alive = 1 },
{ .piece = 'Q', .alive = 1 },
{ .piece = 'Q', .alive = 1 }
}
},
{
.pos = {{ .piece = 'B', .alive = 1 },
{ .piece = 'B', .alive = 1 },
{ .piece = 'B', .alive = 1 }
}
},
{
.pos = {{ .piece = 'K', .alive = 1 },
{ .piece = 'K', .alive = 1 },
{ .piece = 'K', .alive = 1 }
}
}
};
看来行得通。只需注意大括号的位置,请尝试理解您正在输入的内容。这是阅读答案的方法:
忠告:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句