Archived

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

McZ

error when use of static class member

Recommended Posts

I cant use any Static tools in my base shader.. why do I get this error ? cShaderBase { public: class cShaderTools { ... ... }; static cShaderTools Tools; ... ... }; error LNK2001: unresolved external symbol "public: static class cShaderBase::cShaderTools cShaderBase::Tools" (?Tools@cShaderBase@@2VcShaderTools@1@A)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You need to provide an actual definition of any static member in a .cpp file.

Thus, add in a .cpp file:

cShaderBase::cShaderTools Tools;

Share this post


Link to post
Share on other sites
"cShaderBase {" should be "class cShaderBase {"
and you can''t define a class "cShaderTools" within another class "cShaderBase", I suppose.

Try define "cShaderTools" outside "cShaderBase".

-------------------------------
Anton Karlsson
Klingis Entertainment
Games with silly humor

Just dreaming wont make you (more) skilled in game programming/development.

Share this post


Link to post
Share on other sites
Yes, you can nest class definitions.
Anonymous is right - you specified that your class has a static variable in it, but you must actually create it in a source file somewhere. If you do it in the header you will probably get more linker errors - it has to be declared once and only once.

In other words - putting an int variable in your class doesn''t actually create a variable. You have to create an instance of the class before anything actually happens. Since a static variable only exists in one place and won''t be created when you create an instance of the class, you must create the variable manually.

Share this post


Link to post
Share on other sites
quote:
Original post by Sphax
You can define a class A inside an other class B but as i can remember this class will be kind of "private" (you can create objects of class A only inside class B )

You can create instances of nested classes if you declare them public:
Base::Nested instance;  
STL uses this for iterators:
std::vector< int >::iterator pV;  


[edited by - Enselic on September 2, 2003 6:34:27 AM]

Share this post


Link to post
Share on other sites