Jump to content
  • Advertisement


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


Global variables within a class, or something like that

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

OK, say I have 4 classes, A,B,C, and D. Now A has a pointer to D, and an array of B, which has an array of C. Now I need to know how I can get B and C both to have a pointer to the D class that is stored within A without having to declare a pointer to it within B and C and setting it all up. I think you do it using static, but I can''t get it to work yet. I get some linker errors and what not. Can anyone post some examples of how this is done?

Share this post

Link to post
Share on other sites
Well. u can declare a global pointer of D and extern to other files. Or u can send in the pointer of D by reference to both B and C.If u use static u must declare in both the .H and .CPP

class A {
static int *myint;

// .CPP
int A::myint = 0;

This will avoid your linking error.

Share this post

Link to post
Share on other sites
Ok, but how would I declare it in the CPP if the static member is a pointer to a class contained within another class, would I just declare it as NULL then have a function to initialize it?

P.S. I don''t have my code with me so I can''t fiddle around with it yet

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!