Static member variables of template class 
Author Message
 Static member variables of template class

Static member variables of non primitive types in template
classes leads to the linker error (VC+ 5.0):

TemplateTest.o : fatal error LNK1179: invalid or corrupt file: Comdat

Example:

class B {
  B() {}
  ~B() {}

Quote:
};

template<class T1, class T2>
class T {
  T() {}
  ~T() {}
  static B comp;

Quote:
};

The error occurs if the template is resolved two times
with the same first argument type but with different
second type.

T<B, int> t1;
T<B, float> t2;

What's wrong with this code?



Sun, 10 Jun 2001 03:00:00 GMT  
 Static member variables of template class

Quote:

>Static member variables of non primitive types in template
>classes leads to the linker error (VC+ 5.0):

>TemplateTest.o : fatal error LNK1179: invalid or corrupt file: Comdat

>Example:

>class B {
>  B() {}
>  ~B() {}
>};

>template<class T1, class T2>
>class T {
>  T() {}
>  ~T() {}
>  static B comp;
>};

>The error occurs if the template is resolved two times
>with the same first argument type but with different
>second type.

>T<B, int> t1;
>T<B, float> t2;

>What's wrong with this code?

I don't have VC5 installed anymore, but where's the definition of the comp
member? Try adding the following after the class T definition:

template<class T1,class T2> B T<T1,T2>::comp;

--
Doug Harrison



Sun, 10 Jun 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. static template class member variable in DLL

2. template classes with static members

3. static data member of template class

4. Initialization of static data member of template class

5. template classes with static members

6. Static member definition of template class fails

7. Static member definition of template class fails

8. static members in template class across DLL's

9. template classes with static members

10. static member variable inside class

11. LNK1169 & static const class member variables

12. write to static class member variable...

 

 
Powered by phpBB® Forum Software