Hi. I have a question about static members of a templated class. I am getting an undefined symbols error from the linker. My templated class:
template <class T> class RefCountPtr { public: RefCountPtr(T *ptr) : p(ptr) { QMutexLocker lckr(&cmLock); ++countMap[p]; } ~RefCountPtr() { QMutexLocker lckr(&cmLock); --countMap[p]; if (countMap[p] == 0) { delete p; } }
T* operator->() { return p; }
bool isNull() { return (NULL==p); }
private: T * p; static QMutex cmLock; static map<T *, int> countMap; };
Then in another header, I have this: typedef RefCountPtr<Credentials> CredentialsPtr
Then in a .cpp file, I have the following: template <> QMutex RefCountPtr<Credentials>::cmLock; template <> map<Credentials*, int> RefCountPtr<Credentials>::countMap;
I am seeing the following linker error:
/usr/bin/ld: Undefined symbols: RefCountPtr<Credentials>::cmLock RefCountPtr<Credentials>::countMap
I thought I was defining the static members. Any idea why I'm seeing this and what I can do to fix it?
TIA
Brant Sears
|