This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]