Skip to main content
gamedev.net
🔒 Locked

Global declarations

Started by Shadows 0 replies 650+ views
Original Post
Shadows
Shadows
Ok here'' my newbie C++ question: How do you declare a variable, for example an HDC so that it can be used in the whole project and not only in the currently used class. Thanks Regards Shadows
chiuyan
chiuyan
you just declare it in one cpp file like so

HDC g_hMyGlobalDC;

and in any file that needs to access it, you extern it like so

extern HDC g_hMyGlobalDC;

this way, the variable is only declared once (int the first cpp file), but any other file that needs to access it knows that it is defined somewhere.

HTH
--michael

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.