I have a game, stripped down for the problem, a GameHandler class, a Game class, and a Grid class.
The GameHandler class has a declaration of a Game object in its header file. The GameHandler constructor then re-constructs the Game object, so
game = Game();
The game has a declaration of a pointer to a Grid object in it’s header file. The constructor then defines that Grid object:
grid = new Grid(x, y, z);
I can then proceed to play the game all the way through to the end (by death or completion). When I finish the game, the GameHandler gives me the option of starting again, and to do this I figured I would simply reset the game states and then call
game = Game();
again. This doesn’t complain, it does seem to create a new game object, which in turn creates a new grid. This time round though, after constructing the grid, using VS2010 and looking at the locals, by the time the grid gets round to updating or drawing, the locations of all the variables inside the grid are pointing to 0xfeeefef2 or similar, which is data that has been deleted during the running of the program according to a few searches. The only place this is deleted is in the destructor of the Game.
So my assumption at the moment is that I’m overwriting the game object and then the object I’ve overwritten has decided to call it’s destructor which in turn wipes out the grid, leaving it empty. I honestly have no clue, so any insight would be good.
You forgot to define a copy constructor and assignment operator, and one of your
Games is destroying theGridin its destructor — aGridthat is used by otherGames because the pointer was copied.Guessing: