Original Post
Look at my files:
main.cpp
#include "Timer.h"
CTimer timer;
int WINAPI WinMani(...) {...}
Timer.cpp
#include "Timer.h"
std::list<CTimer *> CTimer::m_List;
CTimer::CTimer()
{
m_List.insert(m_List.begin(), this);
...
}
Timer.h
#include <list>
class CTimer
{
public:
CTimer();
...
protected:
static std::list<CTimer*> m_List;
};
I hope I wrote this correct; i didn't copy'n'paste;
The problem is that main.cpp is linked before Timer.cpp.
In main.cpp I declare one CTimer-var, so the consttructor is called. But the static list-var is still not initialised, so the m_List.include()-call failes.
If I declare teh timer-var in may main function, it works correct, because teh global variables are initialised first, but sometimes, i need a global timer.
[edited by - Matheass on May 4, 2004 3:22:34 PM]
[edited by - Matheass on May 4, 2004 3:23:46 PM]