c++ 静态变量
You will need to define the static variable, even if it is not initialized explicitly. That is what is missing in your code. You should have provided a simple example to reproduce the issue, but for your convenience I am providing one which works.
main.cpp
class Foo { public: static int si; static void bar(); }; int Foo::si = 0; // By default, it will be initialized to zero though. void Foo::bar() { Foo::si = 10; }; int main() { Foo::bar(); return 0; }
===================================================================
The correct code is (.cpp):
#include "rtnamedinstance.h" // Initialize static members int RtNamedInstance::_nextInstanceNumber = 0; QMutex RtNamedInstance::_syncObj(QMutex::Recursive); RtNamedInstance::RtNamedInstance(QString instanceName) { QMutexLocker locker(&_syncObj); // [... other code here ...] }