Jump to content
  • Advertisement

Archived

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

G a m e D e v

global with multiple files

This topic is 6237 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 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.

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

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!