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
  • 94,125
  • 30
  • 188
  • 241
Marl
  • 1,492
  • 2
  • 22
  • 37

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
  • 120,358
  • 21
  • 212
  • 242
  • Can't accept answer in 6mins. :P This is the right answer. Thanks for providing it. – Marl Jul 22 '13 at 08:31