Program crashing at finish

Hello!

I'm trying to make a simple Tic-Tac-Toe game, but I'm encountering a strange problem.
Here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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 am using CodeBlocks 10.05 with GCC 4.4.1-tdm-2.
Last edited on
Well, the only thing that is going to happen after the cout and before main returns is Game's destructor will run. What does the destructor do?
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?
Last edited on
No. Something else must be wrong. You'll have to post the code for Game.
Topic archived. No new replies allowed.