Archived

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

31337

Bizare Static Variables

Recommended Posts

For some reason, I set a static variable in what I will call class A from class B''s constructor. Later when a function in class A look''s at the static variable (which happens to be a pointer to class B) it is set to NULL! What in the dickens could be causing this? This variable is only being set once, and frankly I''m stumped on this one. Any ideas? Thanks

Share this post


Link to post
Share on other sites
Is the instance of class B a global variable? Also, do you initialize the static variable of class A to NULL when it''s declared? Since the order of initialization of global variables isn''t guaranteed, it could be that class B is instantiated before the static variable is instantiated, so the static variable doesn''t exist when the constructor is called (bad stuff happening if so), and when the static variable finally is created it''s initialized to NULL.

This is one possible case. But I don''t have specifics

Share this post


Link to post
Share on other sites