• 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: Brant Sears <email@hidden>
  • Date: Mon, 27 Aug 2007 14:33:22 -0400

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;


On Aug 27, 2007, at 2:29 PM, Brant Sears wrote:

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

 _______________________________________________
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

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

  • Prev by Date: Question about static members of templated classes.
  • Next by Date: Re: Placing a spotlight importer into a Applications bundle
  • Previous by thread: Question about static members of templated classes.
  • Next by thread: Re: [SOLVED] Question about static members of templated classes.
  • Index(es):
    • Date
    • Thread