c++ - How can I dereference this 2D dynamic array? -
i having issues dereferencing 2d dynamic array in if statement's condition on line 5.
typedef char* chararrayptr; void reserveseat(chararrayptr *m, char row, char seatletter){ for(int j = 1; j < 5; j++){ if(m[row - 1][j] == seatletter) m[row - 1][j] = 'x'; } }
i've tried putting * in front, error message:
indirection requires pointer operand ('int' invalid)
any appreciated, in advance.
if mean dereference 2d array operator *, please try following.
typedef char* chararrayptr; void reserveseat(chararrayptr *m, char row, char seatletter){ for(int j = 1; j < 5; j++){ //if(m[row - 1][j] == seatletter) if( *( (char*)m + (row - 1)*5 + j ) == seatletter) m[row - 1][j] = 'x'; } }
Comments
Post a Comment