Jump to content
  • Advertisement
Sign in to follow this  
cptrnet

unresolved external symbol

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

Hi, I am using c++.net, stl. I am having trouble with some classes in my library. My first class is a base object class that has the constructor register with an object manager( my second class ). The object manager has all static methods, and a static vector that holds my objects. The thing is my object class needs my objectmanager class, and my objectmanager class needs my object class. I have a main include header where i include the object class first then the manager second. Sometimes it works but it doesn't call the static methods. Then I commented some code out then uncommented and now I am getting an unresolved external symbol on my vector that holds the objects. I've tried everything like putting predefined classes at the top, switching the order i include headers, commenting, uncommenting code. Let me show you my code.

//main include header

#include <string>
#include <vector>
#include "xObject.h"
#include "xObjectManager.h"



xObject::xObject(void)
{
   xObjectManager::Add(this);
   m_ID = xObjectManager::Count();
   m_strName = "Object_";// + m_ID;
}



class xObjectManager
{

private:

	static std::vector<xObject*> m_xObjects;

public:

	static size_t Count();
	static void Add(xObject *obj);
};

int xObjectManager::Count()
{
  return (int)m_xObjects.size();
}

void xObjectManager::Add(xObject *obj)
{
  m_xObjects.push_back(obj);
}


The exact error that I am getting is error LNK2001: unresolved external symbol "private: static class std::vector<class xObject *,class std::allocator<class xObject *> > xObjectManager::m_xObjects" (?m_xObjects@xObjectManager@@0V?$vector@PAVxObject@@V?$allocator@PAVxObject@@@std@@@std@@A)

Share this post


Link to post
Share on other sites
Advertisement
Since m_xObjects is declared static, you have to provide a real instance of the object in your .cpp file. Add a line like the following in your class implementation (.cpp) file:


std::vector<xObject*> xObjectManager::m_xObjects;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!