static members of template classes

From: Alibek (alibekj_at_yahoo.com)
Date: 12/16/03


Date: 15 Dec 2003 16:53:22 -0800

Hello !

I have here template class with
static members. and I put definition of the static member in the same
.h file where the class was declared.

however, we are getting very stange errors, because static member
occupy same place as some other non-static variables. and so
application crashes. compiler somehow allocates same place for them.

I first thought that it is because definition of static member should
be done inside translation unit (that is inside cpp file). otherwise
One Definition Rule is broken.
but in the case of template classes I do not know exactly. C++
standard says it is ok to put definition of static member into same .h
file.

then I moved definition of static member to cpp file, application
stopped crashing, but Purify still shows ABW errors.

does somebody know - is wrong or not to put definition of static
member of template class into same .h file?

I am using 2.96 gcc (g++) compiler.

thanks !

br.,
Alibek.



Relevant Pages

  • Re: static members of template classes
    ... > however, we are getting very stange errors, because static member ... > be done inside translation unit (that is inside cpp file). ... > member of template class into same .h file? ... You're using a compiler that is at least five years old. ...
    (comp.lang.cpp)
  • Re: template class and static variables
    ... I think you can define a base class which has a static member. ... class A inherits from it. ... > I have a template class like ...
    (microsoft.public.vc.language)
  • Trouble with a pointer to a static member of a template class
    ... Given the following template class: ... I wish to declare and define a pointer to the static member above. ... But the compiler tells me it is unable to do a suitable conversion ...
    (comp.lang.cpp)
  • initializing static member in a template class
    ... In a non-template class, one would ... initialize the static member in the cpp file, ... Where to initialize the static variable then? ...
    (microsoft.public.vc.language)
  • Re: export static public member
    ... Did you link the .obj file in the second project? ... I have defined the instance of the static member in the CPP file like this ... I use class CExportMe in project A, ...
    (microsoft.public.vc.mfc)