Using Globals Variables between files
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
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
extern int flag[250];
-Ironblayde
Aeon Software
I didn''t mean to write the extern that way. I edited the message. It should be like how I originally wrote it.
Still doesn''t work.
Still doesn''t work.
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
-Ironblayde
Aeon Software
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement