Sign in to follow this  

unresolved external symbol

Recommended Posts

Hi, I am using, 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"

   m_ID = xObjectManager::Count();
   m_strName = "Object_";// + m_ID;

class xObjectManager


	static std::vector<xObject*> m_xObjects;


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

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

void xObjectManager::Add(xObject *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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this