I took a programming class at university this semester, just out of curiosity. We're doing C++ and I enjoyed it a lot, but the last two weeks have been rather steep for me and heres what troubles my mind:
I'm given a class interface as follows:
class GameOfLife(int rows, int cols);
public:
GameOfLife();
void clear();
void set(int row, int col, int value);
void set(int row, int col, const char* values);
int get(int row, int col);
void print();
void advance();
};
First thing im being asked to do is to implement the constructor so that it allocates memory for a board with the amount of rows and cols passed in the argument. I thought i understood constructors but with this one I'm pretty lost. After i declared int rows and cols in the private section i thought about something along the lines of
GameOfLife::GameOfLife(int x, int y){
rows = x;
cols = y;
board = new int* [rows];
But neither do i know how to handle the second dimension of the board without the compiler yelling at me nor do i know how to test if new memory is actually allocated properly. Any help? :(
Thanks in advance!