Hm your class body looks fine. Are you doing something weird like #including a cpp file or something? And you're sure you don't have a second definition of these functions somewhere?
Side point / Lesson in OOP:
Your copy ctor is still wrong. The ctor is run
first so calling initializeBoard to create the array will not work in this case because the copy ctor is trying to write the the array:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
Board::Board(const Board& brd){ // <- copy ctor
this->numRows=brd.numRows;
this->numCols=brd.numCols;
// this->board is uninitialized. initializeBoard has not been called yet
for(int i=0; i<brd.numRows; i++){
for(int j=0; j<brd.numCols; j++){
this->board [i] [j]=brd.board[i] [j]; //<- EXPLODE!!!!
// trying to write to this->board but it hasn't
// been initialized yet
}
}
}
|
Further, initializeBoard kind of defeats the point of having a constructor. The constructor is supposed to do the initializing.
At the very least your ctor should be null-ing the board pointer so you don't try to delete a bad pointer in your dtor. Example:
1 2 3 4 5 6 7
|
int main()
{
{
Board a; // <- ctor called... 'board' left uninitialized
// <- do not call initializeBoard
} // <- dtor called here... you try to delete a.board... but a.board is unitialized
// so deleting it will probably make your program explode
|
In order for your class to work as expected... you are requiring the user of the class have to call functions in a very specific order.
First: ctor
second: setBoard
third: initializeBoard
If they call those things in the wrong order, or forget to call one of them... not only will the class not work as expected... but it will likely EXPLODE and cause the program to crash.
Can you imagine if classes like std::string, std::vector, etc worked like that? They'd be much, much harder to use.
Also... if they call initializeBoard multiple times... then your class will leak memory. And if you call setBoard after initializeBoard, then your board will have incorrect values for the number of rows/columns.
The whole point of OOP is to make objects "self contained" so the user has to actually try very hard to misuse them. You are treating functions like they are simple getters/setters (setBoard sets your width/height.... initializeBoard sets your board). Getters/setters are bad OOP.
But anyway I'll stop talking your ear off because this is not related to your actual problem.