0

I want to keep track of the instance of MyClass, so I have add a private static variable std::map<int,MyClass*> inside MyClass. The problem now is it causes unresolved external symbol, which I don't know how to debug. How can I resolve this?

Note: I'm a seasoned Java programmer and novice C++ programmer, and also I'll be using this as a JNI dll, that is why I need to keep track the instances of MyClass.

Maroun
  • 91,013
  • 29
  • 181
  • 233
Marl
  • 1,480
  • 2
  • 22
  • 33

1 Answers1

5

You probably haven't provided the implementation:

MyClass.h:

class MyClass {
private:
    static std::map<int, MyClass *> m_instances;
...
};

MyClass.cpp:

#include "MyClass.h"

// Add this
std::map<int, MyClass *> MyClass::m_instances;
trojanfoe
  • 118,129
  • 19
  • 204
  • 237
  • Can't accept answer in 6mins. :P This is the right answer. Thanks for providing it. – Marl Jul 22 '13 at 08:31