Re: [SOLVED] Question about static members of templated classes.
Re: [SOLVED] Question about static members of templated classes.
- Subject: Re: [SOLVED] Question about static members of templated classes.
- From: Steve Checkoway <email@hidden>
- Date: Mon, 27 Aug 2007 17:28:53 -0700
On Aug 27, 2007, at 11:33 AM, Brant Sears wrote:
Sorry everyone. I figured this out seconds after posting the question.
The answer is that I needed to define the static members like this:
template <class Credentials> QMutex RefCountPtr<Credentials>::cmLock;
template <class Credentials> map<Credentials*, int>
RefCountPtr<Credentials>::countMap;
Actually, this isn't defining the static members, it's declaring them
and is no different from having written
template <class T> QMutex RefCountPtr<T>::cmLock;
template <class T> map<T*,int> RefCounterPtr<T>::countMap;
I'm actually a little surprised this fixed anything for you. My
experience has been that for this to work, you need to define the
static members. In the header file, you can use:
template <class T> QMutex RefCountPtr<T>::cmLock = QMutex();
template <class T> map<T*,int> RefCounterPtr<T>::countMap =
map<T*,int>();
C++ is very confusing on this and I usually have to read the standard
to get it right. This bit is in 14.5.1.3.1 [temp.static] of the c++98
standard.
On Aug 27, 2007, at 2:29 PM, Brant Sears wrote:
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:
[...]
I thought I was defining the static members. Any idea why I'm seeing
this and what I can do to fix it?
You can define them like this, but you actually need to define them as
above:
template <> QMutex RefCountPtr<Credentials>::cmLock = QMutex();
template <> map<Credentials*, int> RefCountPtr<Credentials>::countMap
= map<Credentials*,int>();
I hope this helps in the future, even though you have this code
working now.
--
Steve Checkoway
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden