I created a message-only window class, and I'm trying to map the HWND back to objects with these descriptors. I am trying to do this using a private static std::map<HWND, CMyClass*>belonging to a class, for example:
MyClass.h:
class CMyClass
{
...
private:
HWND m_hWnd;
HINSTANCE m_hInstance;
LPCSTR m_szClassName;
static std::map<HWND, CMyClass*> s_mapHandles;
...
};
MyClass.cpp:
std::map<HWND, CMyClass*> CMyClass::s_mapHandles;
but when I try to add to the map, the program crashes. I tried three different forms and they all give the same error:
...
m_hWnd = ::CreateWindowEx(0, m_szClassName, "Message Window", 0, 0, 0, 0, 0, HWND_MESSAGE, 0, m_hInstance, 0);
s_mapHandles.insert(pair<HWND, CMyClass*>(m_hWnd, this));
or
...
s_mapHandles.insert(s_mapHandles.end(), pair<HWND, CMyClass*>(m_hWnd, this));
or even
...
s_mapHandles[m_hWnd] = this;
In each case, a call fails _Root(), which tries to return _Parent(_Myhead); _Parent(_Myhead)returns (_Nodepref)(*_Myhead)._Parentwhich fails because it _Myheadis null.
How to initialize a card so that its head is not zero, and I can insert things without failing? Sorry if I explained this poorly - I'm new to C ++.