Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Coaster Kev

Using Globals Variables between files

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

I have a system of flags for my game, which I decided to put aside into an array: Example1.cpp int flag[250] = 0; //Flag Array all set to zero Well, I want to use the global var in other files so I added to the headers for the files the line: Example2.h extern int flag[250]; Then I try to access it: Example2.cpp int accessflag(); { flag[5] = 1; return 0; } The problem is that I get the error that flag[5] had not been declared. Could some one give me so hints here or give me another (or better) way to do what I'm trying to do. Thanks. Edited by - Coaster Kev on 8/28/00 7:17:14 PM

Share this post


Link to post
Share on other sites
Advertisement
When you use ''extern'' to include a global that''s been defined in another source file, don''t include the initialization part of it. So you just want this:

extern int flag[250];

-Ironblayde
 Aeon Software

Share this post


Link to post
Share on other sites
Umm... put the ''extern'' statement in the source file you want to use the array in, not the header file, and see if that does it. I''ve never tried putting ''extern'' statements in a header file before so I don''t know if it works.

-Ironblayde
 Aeon Software

Share this post


Link to post
Share on other sites
I fixed it. It seems the problem was that I accidentally declared the global in my header file, and that was the problem. That''s changed and it works like it''s supposed too.

Share this post


Link to post
Share on other sites

  • 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!