For some reason, even though I've looked and made myself as sure as I can be I'm doing this right, I keep getting exit status -1 in this code. I'm simply trying to create a dynamic 2d array and to fill each value with a 0:
Grid::Grid(int _rows, int _cols){
Grid::rows = _rows;
Grid::cols = _cols;
Grid::grid = new int*[Grid::rows];
for(int i = 0; i < Grid::rows; i++){
Grid::grid[i] = new int[Grid::cols];
}
for(int i = 0; i < 1; i++){
for(int j = 0; j < 1; i++){
Grid::grid[i][j] = 0;
}
}
}
I've done some testing and the code runs fine without the second for loop when I'm trying to fill the array, so I think the problem is there, even though I can't see what would be wrong with it.
Here's the class just in case:
class Grid{
private:
int rows;
int cols;
int** grid;
public:
Grid(int _rows, int _cols);
int getRows(){return rows;}
int getCols(){return cols;}
int** getGrid(){return grid;}
void deleteArray();
};
I'm new to c++, so go easy on me if it's an obvious mistake. Thanks for the help.