So I have a class called Cell, and I need to create a new Cell and put it into a 2d array. I believe the problem is how I created the 2D array. I have looked up how dynamic arrays work but I still can't find the problem. Below is some of my code and the first few errors I get
Cell * board = new Cell[h]; //create new board
for(int i = 0; i < h; i++){
board[i] = new Cell[w];
}
for (int row = 0; row < h; row ++){ //initialize board
for (int col = 0; col < w; col++){
board[row][col] = new Cell;
board[row][col]->status = '#';
board[row][col]->isCovered = true;
}
}
ERRORS:
minesweeper.h: In constructor ‘GameBoard::GameBoard(int, int, int)’:
minesweeper.h:29:17: error: no match for ‘operator=’ (operand types are
‘Cell’ and ‘Cell*’)
board[i] = new Cell[w];
^
minesweeper.h:29:17: note: candidate is:
minesweeper.h:4:8: note: Cell& Cell::operator=(const Cell&)
struct Cell
^
minesweeper.h:4:8: note: no known conversion for argument 1 from ‘Cell*’
to ‘const Cell&’
minesweeper.h:33:16: error: no match for ‘operator[]’ (operand types are
‘Cell’ and ‘int’)
board[row][col] = new Cell;
^
minesweeper.h:34:16: error: no match for ‘operator[]’ (operand types are
‘Cell’ and ‘int’)
board[row][col]->status = '#';
^
int. That way you can iron these problems out before you introduce a lot of new unknowns.