Passing a 2d dynamic array to a function in C++

前端 未结 5 1514
长情又很酷
长情又很酷 2021-01-19 23:52

I have this 2d dynamic array and I want to pass it to a function, How would I go about doing that

int ** board;
        board = new int*[boardsize];

                


        
5条回答
  •  余生分开走
    2021-01-20 00:23

    You should define a function to take this kind of argument

    void func(int **board) {
        for (int i=0; i

    If boardsize or size are not globlal, you can pass it through parameters.

    void func(int **board, int boardsize, int size) {
        for (int i=0; i

提交回复
热议问题