C ++ Struct line(int x [3] = {1,2,3};)[array]

时间:2015-11-19 17:01:23

标签: c++ c arrays struct line

struct Mouse_k
{
    int kords_X[3] = { 100, 200, 300 };
    int kords_Y[3] = { 900, 800, 700 };
}mouse;
  

错误:无法为数组指定显式初始值设定项。

我不想使用:

struct Mouse_k
{
    int kords_X[3];
    int kords_Y[3];
}mouse;

void main()
{
    mouse.kords_X[0] = 100;
    mouse.kords_X[1] = 200;
    mouse.kords_X[2] = 300;
}

1 个答案:

答案 0 :(得分:0)

试试这个:

struct Mouse_k
{
    int kords_X[3];
    int kords_Y[3];
}mouse = {{100, 100, 100}, {200, 200, 200}};