初始化值太多

时间:2017-05-31 05:09:23

标签: c++ arrays

我有一个指向二维数组的指针,我已声明如下:

int **gameBoard[3][3];

然后将其添加到类构造函数中:

**gameBoard = { 
                {0,0,0}, 
                {0,0,0}, //<--that's the specific line I am getting the error in
                {0,0,0} 
              };

我甚至将其声明为20x20,但每次都会出现相同的错误:

too many initializer values

任何帮助?

1 个答案:

答案 0 :(得分:1)

您应该声明并初始化二维数组,如下所示:

int gameBoard[3][3] = { 
                {0,0,0}, 
                {0,0,0}, 
                {0,0,0} 
                };