0
const int width = 100, height = 100;
void clearBoard(bool *board[]);

int main(int argc, char *argv[])
{

    bool gameboard[width][height];
    clearBoard(gameboard);

    QApplication a(argc, argv);
    MainWindow window;
    window.show();

    return a.exec();
}

void clearBoard(bool *board[]){
       for(int x = 0; x < width; x++)
        for(int y = 0; y < height; y++)
            board[x][y] = false;
}

The error at hand is:

C2664: 'void clearBoard(bool *[])' : cannot convert argument 1 from 'bool [100][100]' to 'bool *[]'

I think I have the basic understanding of how pointers work, and 2D pointer, but for some reason this won't work. Would love it if someone could explain what I'm getting wrong.

Patidati
  • 1,048
  • 2
  • 12
  • 19

1 Answers1

1

When passing an n-dimensional array as a function argument, you can let only the first dimension be implicit. Please try:

void clearBoard(bool board[][height]){
       for(int x = 0; x < width; x++)
        for(int y = 0; y < height; y++)
            board[x][y] = false;
}
hamid attar
  • 388
  • 1
  • 8