Link errors with statics

Started by
1 comment, last by MelvinElvin 22 years, 8 months ago
Using MSVC++ 6, whenever i create a static variable for a class, it compiles fun but then i get a link error saying: "unresolved external symbol" followed by the name of the static i declared. If anyone can figure out what I''m doing wrong from this vague description, I''d be extremely grateful. I haven''t used statics all that much before, so it''s probably something pretty simple i''m not doing. Thanks a lot. MelvinElvin
GSACP: GameDev Society Against Crap PostingTo join: Put these lines in your signature and don't post crap!
Advertisement

You have to do this:

//.hclass CFoo{private:static int m_Foo;};//.cppint CFoo::m_Foo=0;




What the hells!
What the hells!
In case the previous poster''s message wasn''t clear (it is perfectly correct, but might be confusing, I suppose): The reason you are getting a linker error is because you are initializing the static variable in the header file, and not in the .cpp.

Statics should be initialized in the .cpp in which you define the class member functions.

This topic is closed to new replies.

Advertisement