Advertisement Jump to content
Sign in to follow this  

Static variables in classes

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

Hello I have question to You. Suppose we have a class: class CClass { public: static int st_iBlah; }; Now we have header with this class in our application and in dynamic library. Somewhere we load dll in application. Now my question is: How to connect this classes(? one class but in different "places") to share only one instance of st_iBlah between application and dll ? Other exapmle: There is static library "core" which contain singleton CCore and we link it to application and to dynamic library. Again somewhere in application we load dll and i want use in this dll the same CCore object that is used in application. How to do it ?

Share this post

Link to post
Share on other sites
You need to used the __declspec attribute, assuming you're using MS compiler. However, the argument to the attribute depends on the way it's used, so, in the header have:

#define CLASS_ATTRIBUTE __declspec (dllexport)
#define CLASS_ATTRIBUTE __declspec (dllimport)

// stuff here as before

When you compile the DLL with the class defined in it, define COMPILING_DLL_WITH_CLASS. For any clients of the class, don't define that symbol.


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!