• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [SOLVED] Question about static members of templated classes.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Question about static members of templated classes. (From: Brant Sears <email@hidden>)
 >Re: [SOLVED] Question about static members of templated classes. (From: Brant Sears <email@hidden>)

  • Prev by Date: 1 GB limit on total object files size for linking?
  • Next by Date: Re: 1 GB limit on total object files size for linking?
  • Previous by thread: Re: [SOLVED] Question about static members of templated classes.
  • Next by thread: 1 GB limit on total object files size for linking?
  • Index(es):
    • Date
    • Thread