Create a matrix struct

So i am trying to create a structure that contains information about a matrix, and trying to initialize that matrix by putting every element 0. I get no errors, but after compiling the program crashes, any help?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
struct board_s {int length; int width; int **m;};
typedef board_s *board;
    
board newboard(int inputlength, int inputwidth){
    board play = new board_s;
    play->length = inputlength;
    play->width = inputwidth;
        //CREATE A MATRIX
        int **m = new int*[inputlength];
        int i=0;int j;
while (i<inputlength) {
    play->m[i]=new int[inputwidth];
    j=0; while (j<inputwidth) {play->m[i][j]=0; j++;};
    i++;};
    
return play;    
}; 
there should be a compile problem.

play is not a pointer, and you can not use new with it.
Play is a pointer, notice the typedef.
There is no compile problem.
Topic archived. No new replies allowed.