Jump to content
  • Advertisement
Sign in to follow this  
Erector

Static pointer question

This topic is 4524 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

After taking a year off from game development I've decided to try and revive my old hobby. So I picked up one of my old game books and immediately ran into something I didn't quite understand. In Michael Morrisons "Beginning Game Programming" he starts off with a game engine design. In this design he uses a static pointer to the GameEngine class inside the actual game engine. He then uses this static pointer within GameEngine to call methods contained within it. Here's a brief snippet to try and describe what i'm talking about: //In GameEngine.cpp GameEngine *GameEngine::m_pGameEngine = NULL; if (!GameEngine::GetEngine()->Initialize(iCmdShow)) return FALSE; //end snippet Okay, so I'm struggling here with the concept of static. I understand what it means so far as it being the exact same m_pGameEngine variable no matter how many GameEngine objects exist, but I don't understand the need to make a static variable here. Why can I not just call Initialize directly at this point? if (!GameEngine::Initialize(iCmdShow)) gives me errors: d:\temp\Blizzard\GameEngine.cpp(29): error C2352: 'GameEngine::Initialize' : illegal call of non-static member function Why doesnt the code generate simliar errors when he later calls simple set functions (defined in the header file): SetWindow(hWindow); Here he didn't have to use the static pointer to the game engine object to access methods inside the file. What am I missing. TIA

Share this post


Link to post
Share on other sites
Advertisement

This topic is 4524 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!