Jump to content
  • Advertisement
Sign in to follow this  
Kimau

Global Timer

This topic is 4546 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

Okay this is a real newbie C++ question but I need to ask it. I've got a global timer class I need to link. Now for my other global class I use a singleton and it works fine. However my g_DeltaTimer doesn't seem to work. It needs to be a global in a header with some defines. its set by the main game loop in main.cpp but needs to be accessed across the program. I tried put in "support.h" static unsigned long g_DeltaTimer; But its always Zero in another class when I call it. Please will someone tell me the simple solution so I can stop beating my head around in stupidity.

Share this post


Link to post
Share on other sites
Advertisement
"support.h"
extern unsigned long g_DeltaTimer;

"some_file.cpp"
unsigned long g_DeltaTimer;

Would that fix it?

Share this post


Link to post
Share on other sites
That seems to generate a linking error. I'm not at machine atm but I'll paste error when I get home tonight.

Share this post


Link to post
Share on other sites
Include Gaurds??? Not that I'm aware of but I dont know what they are.

Share this post


Link to post
Share on other sites
Stops the header being included more than once.

#ifndef MY_GUARD
#define MY_GUARD

[header file]

#endif

Share this post


Link to post
Share on other sites
Quote:
Original post by Kimau
...
I tried put in "support.h"
static unsigned long g_DeltaTimer;


That code will define a separate variable named g_DeltaTimer in every file support.h is included in.

If you follow what simon10k wrote, you will have a single variable accessible from any file that includes support.h.

Share this post


Link to post
Share on other sites
Thanks once I removed the include gaurds it all works.

Yeah it all works now.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!