int main()
{
Game game;
while (true)
{
game.getmove(); //Reads a move from the console
if ( game.win() ) { cout <<"we have a winner;";break;} //win returns 1 for x wins, -1 for 0 wins and 0 otherwise
game.makemove(); //puts a 0 in the first free cell found
if ( game.win() ) { cout <<"we have a winner;";break;}
game.print(); //outputs the board to the console
}
cout << "returning"; //lets me know the while ended
//Here is where it goes wrong
return 0;
}
I am using a class called Game which stores all the methods I used. I tested each one individually, so I think the problem lies somewhere else. Still, let me know if you want to see any of the methods.
The program works fine until exiting the while loop.
The actual problem is that, instead of ending normally, the program crashes after outputting "returning". The error says: "TicTacToe.exe has stopped working".
I've tried commenting the whole code, and writing a simple hello world program, and it works ok.
I didn't write the destructor. I don't know what I'm supposed to write there. My class doesn't use any dynamically alocated memory. It only uses an int[][] and a bool. After reading some tutorials on classed, I understood that I only have to write the destructor if I have to free memory.
Am I doing something wrong?
Edit: I've just written a destructor for my class and it works fine now. I didn't write anything inside it.
Do I always have to do this?