CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2005
    Location
    Canada
    Posts
    40

    Lost information

    Hey guys, I'm currently having some problems with losing variable information (where the pointers point to, the assigned values, etc.) from different header files.


    I have something like this:

    Helper Lib.h
    |
    |
    Player.h
    |
    |
    Common.h
    |
    |
    GameLoop.h


    The GameLoop header includes the Common .h, which includes the Player .h, which includes the HelperLib.h. The HelperLib, Player, and Common .h files contain all static members and methods. Also, most of the members and methods in each of those header files are global. I did this because I don't think I need multiple copies of those functions or members.

    Issue 1: When I startup the GameLoop, I assign an ID (global member in the Player header); and later on the networking engine calls a method, createPlayer, inside the Player header. At this point I need to compare the new-found Player's ID and the assigned ID, but inside the method ID is somehow blank.

    Issue 2: Pretty much the same as Issue 1: When a new Player is created I need to call a function from the Scene class member (static SceneManager* scene - which is a member of the Helper Lib). This class is intialized in the GameLoop, but when I get to the Player creation method, this pointer points to nothing (and as soon as I get out of that method, back to the GameLoop, the pointer seems just fine again).

    Issue 3: I have a global variable (static User* userPlayer) that I intialize inside the Player header. I can see it just fine in the Player header, but when I try to call it from the GameLoop it shows up as a bad pointer.


    I've tried making everything non-static (which I personally don't think makes sense anyways) and ended up with a whole bunch of LNK2005 errors, saying that I already defined the members/functions inside the GameLoop header. But I still have a feeling it's a problem with static definitions.

    I can generally work around this by re-intializing the members inside some of the methods, but I know this would be very inefficient:
    Player[0] = new Player(scene, world, ...);

    Player(SceneManager* scene, World* world) {
    ::scene = scene;
    ::world = world;
    // Now works totally fine
    }


    Does anybody have any other solutions? It'd really help out a lot, I've been trying to get around this problem for a while, and I can't figure it out at all X_x thanks =]

  2. #2
    Join Date
    Apr 2009
    Posts
    598

    Re: Lost information

    You might have static pointers, but the memory pointed by these pointers might have changed. Instead of static User* userPlayer, maybe you could have static User userPlayer.

  3. #3
    Join Date
    Nov 2005
    Location
    Canada
    Posts
    40

    Re: Lost information

    Hey guys =] Thanks for the help. I ended up getting the answer from another forum, I had to use the extern keyword when declaring my variables.

    Forum post here: http://www.jenkinssoftware.com/rakne...p?topic=2559.0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured