This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: Undefined reference for static member of a template class
- From: "Rupert Wood" <me at rupey dot net>
- To: "'Devrim Erdem'" <devrim at vires dot com>
- Cc: <gcc-help at gcc dot gnu dot org>
- Date: Wed, 12 Dec 2001 15:06:12 -0000
- Subject: RE: Undefined reference for static member of a template class
Devrim Erdem wrote:
> I have a template class like this :
:
> static ObjType *mInstance ;
:
> The compiler (gcc 2.95.2-149) reports a undefined refence error
> during linkage. Any ideas ?
Since you didn't tell us, I'll assume that your error looks like this:
Undefined first referenced
symbol in file
Mingleton<ClassA>::mInstance /var/tmp/ccVAIFxr.o
When you declare a static member of a class, templated or not, you must
also define it: you must allocate some storage in one of your source
files so that there is a single, cross-project instantiation of the
static member. Try adding:
ClassA* ClassB::mInstance;
to one of your sources at global (or matching namespace) scope.
Hope that helps,
Rup.