global with multiple files
I have a project in Visual C++ 6 with multiple source files. I want the DirectX objects to be global to all the source files not just the files they are declared in. I tried this:
extern LPDIRECTDRAW7 lpDD=NULL;
The extern statment didnt work. How can I do it?
Thanks.
"Beware of computer programmers that carry screw drivers"
Hmm... Are you sure you used the extern keyword right?
there where you declare the value you don''t use ''extern'' you just declare it normally....
LPDIRECTDRAW7 lpDD=NULL;
in every function where you want to use it.. (draw(), whatever) you use extern LPDIRECTDRAW7 lpDD; then it is available in that function..
cya,
Phil
Visit Rarebyte!
and no!, there are NO kangaroos in Austria (I got this questions a few times over in the states
there where you declare the value you don''t use ''extern'' you just declare it normally....
LPDIRECTDRAW7 lpDD=NULL;
in every function where you want to use it.. (draw(), whatever) you use extern LPDIRECTDRAW7 lpDD; then it is available in that function..
cya,
Phil
Visit Rarebyte!
and no!, there are NO kangaroos in Austria (I got this questions a few times over in the states

Visit Rarebyte! and no!, there are NO kangaroos in Austria (I got this question a few times over in the states ;) )
quote:
Original post by G a m e D e v
I have a project in Visual C++ 6 with multiple source files. I want the DirectX objects to be global to all the source files not just the files they are declared in. I tried this:
extern LPDIRECTDRAW7 lpDD=NULL;
The extern statment didnt work. How can I do it?
Thanks.
If you declare a variable extern, you can''t set it''s value in the declaration... Here''s how you would do that.
in a .H file that you will include in all your files:
extern LPDIRECTDRAW7 lpDD;
in your main file, you do:
LPDIRECTDRAW7 lpDD = NULL;
now, all your files will have access to your globals...
"And that''s the bottom line cause I said so!"
Cyberdrek
Headhunter Soft
A division of DLC Multimedia
Resist Windows XP''s Invasive Production Activation Technology!
"gitty up" -- Kramer
[Cyberdrek | ]
Ok thanks I got it working with variables and functions. But how would I make a class avalible to multiple files using extern?
"Beware of computer programmers that carry screw drivers"
extern is really just for variables, ie. instances of classes or primitive types. Functions and classes are available to any source file that includes the function prototype or class declaration.
If you want to do it with a class I suggest using a singleton.
class singleton
{
private:
// constructor is private, werid huh?
singleton(){};
public:
static singleton& getInstance()
{
static singleton theInstance();
return theInstance;
}
}; // end of class
This way you are ensured a single instance of the class, you access the class through
singleton::getInstance()...
or alias the instance
singlton &single = singleton::getInstance();
single...
The class is created at the first call of getInstance, although
a variation is to have an init method that creates the instance (and ensures the object is properly instantiated).
Patterns are cool, m'kay
Edited by - brad_beveridge on July 19, 2001 7:25:39 PM
class singleton
{
private:
// constructor is private, werid huh?
singleton(){};
public:
static singleton& getInstance()
{
static singleton theInstance();
return theInstance;
}
}; // end of class
This way you are ensured a single instance of the class, you access the class through
singleton::getInstance()...
or alias the instance
singlton &single = singleton::getInstance();
single...
The class is created at the first call of getInstance, although
a variation is to have an init method that creates the instance (and ensures the object is properly instantiated).
Patterns are cool, m'kay
Edited by - brad_beveridge on July 19, 2001 7:25:39 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement