I'm trying to make something like this:
class A
{
static pthread_mutex_t m;
public:
template<typename T>
static void TestFunc(T t) {
pthread_mutex_lock(&m);
}
static void Test()
{
TestFunc(13);
}
};
But receive linker error:
/tmp/cc1HN0fI.o: In function
void A::TestFunc<int>(int)': TReaderThread.cpp:(.text._ZN1A8TestFuncIiEEvT_[_ZN1A8TestFuncIiEEvT_]+0xc): undefined reference toA::m' collect2: error: ld returned 1 exit status make: *** [all] Error 1
It seems that this error happens only when TestFunc is template function. It is small peace of code, I need that TestFunc was template and my mutex was static variable. Is it possible to solve this issue in template approch? P.S. Realy I need to do - implement tracer as singlton(with syncronization for output descriptor).
m, correct?