Jump to content
  • Advertisement


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

Greg K

static keyword

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

I am using a static variable log of type class FileLog. FileLog is a basic class that logs text to a file. I want one log for all my instances of type Object. class Object { public: static void createLog() {log.create("LogObject.txt");} static void destroyLog() {log.destroy();} private: static class FileLog log; }; I figure I should then be able to call: Object::createLog(); Object::destroyLog(); from the main program and inside Object I would be able to access log to output messages. This does not work. It gives me this error: : error LNK2001: unresolved external symbol "protected: static class FileLog Object::log" (?log@Object@@1VFileLog@@A) : fatal error LNK1120: 1 unresolved externals Can anyone help me? -Greg Koreman

Share this post

Link to post
Share on other sites
In exactly one source file you need to put the line:

FileLog Object::log;

This will create the storage for the log class.

Share this post

Link to post
Share on other sites
Off topic (this doesn't apply to original post, so there is no confusion), but it gets so much more complicated when you have a templated class with a template static member with a constructor that takes parameters. Whew. Basically...

template <class T> std::map<std::string, T> TManager<T>::m_map(T::CompFunctor);

instead of a simple

FileLog object::log;

Yes, I know, I probably should look into a redesign.

EDIT: Damn < and > with HTML!

[edited by - Neosmyle on November 5, 2002 12:40:07 AM]

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!