Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7026663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:08:50+00:00 2026-05-28T00:08:50+00:00

I have a game, stripped down for the problem, a GameHandler class, a Game

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:08:50+00:00Added an answer on May 28, 2026 at 12:08 am

    You forgot to define a copy constructor and assignment operator, and one of your Games is destroying the Grid in its destructor — a Grid that is used by other Games because the pointer was copied.


    Guessing:

    class Game {
    
       Grid* grid;
    
       public:
         Game(int x, int y, int z) : grid(0) {
            grid = new Grid(x, y, z);
         };
    
         ~Game() {
            delete grid;
         }
    
    
         /* You forgot these: */
    
         Game(Game const& src) : grid(0) {
            grid = new Grid(*(src.grid));
         }
    
         Game& operator=(Game other) {
            swap(other);
            return *this;
         }
    
         void swap(Game& other) {
            // swap all the members (and base subobject, if applicable) with other
            std::swap(grid, other.grid);
         }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem with the XNA framework, I have a stripped down version
If have I have a game engine that has multiple threads that all work
I have this game where balloons are coming from bottom and player has to
I have a game object which processed in two completely different places. In Contact
I have a game in RoR. The game breaks down like this. There are
I have a game tree that is too big to walk in its entirety.
I'm writing a game using Irrlicht. And I have problem. I have game in
I have a game which has surfaceview and running on a thread. if I
I have a game engine design written in C++ where a platform-independent game object
I have a game consisting of ships that fly around on a 2d grid.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.