   Initing static vars in a templated class
  I can''t figure out how to initialize the member variable polarized. Im using VS 7.0. This is my first attempt at making a class with templated template parmeters.   template <class T,template <class> class creation_policy = create_using_new,template <class> class lifetime_policy = default_lifetime,template <class> class threading_policy = single_threaded>class atom {...static bool polarized;};Tried playing around with the syntax and keep comming up with this.C2687: cannot define a nested UDT of a template class out of lineBeing static, i cant define it inline, right? 
  You define it for each instantiation of the template. // In a header Foo.htemplate <typename T>class Foo    {    public:   static int size;    };// end// In some XYZ.cppint Foo<char>::size = sizeof(char);int Foo<int>::size = sizeof(int);int Foo<float>::size = sizeof(float);// ...etc Kami no Itte ga ore ni zettai naru! ;  EDIT: DAMN IT... why did i bother? i type to slow  [edited by - MrBeaner on February 14, 2004 10:12:54 PM];  This is a limitation of the MSVC 7.0 compiler. It doesn't play happily with declaring static members for template class that have template class template parameters. What you need to do is create a proxy or holder class templated on the specific template class being instantiated and then you can use the holder's static data. For this case, I think it would look like this: template <class A>struct AtomStaticHolder {  static bool polarized;};template <class A>bool AtomStaticHolder<A>::polarized;template <class T,template <class> class creation_policy = create_using_new,template <class> class lifetime_policy = default_lifetime,template <class> class threading_policy = single_threaded>class atom {  typedef AtomStaticHolder<atom> MyStaticHolder;};Then inside your atom class, instead of referring to polarized directly, you'd use MyStaticHolder::polarized.Judging from your code, I'd say you were familiar with the Loki library. If you go to the Loki's sourceforge page you can download a copy of the library, including the code ported to MSVC 7.0. It shows how to implement many of the work-arounds necessary for that compiler.edit: !#@$ smiley code   [edited by - SiCrane on February 14, 2004 10:15:35 PM];  tangentz: your code is outdated and inflexible.On MSVC 7 and above, this is better: // In a header Foo.htemplate <typename T>class Foo {  public:    static int size;};template <typename T>int Foo<T>::size = sizeof(T);Please note that you don''t need to put the static''s initialization in a source file, it all goes in the header. The compiler will instantiate the static for every translation unit and every template specialization used and place the necessary symbols in the object files. The linker will then combine and repatch the symbol references. ;  Okay, thanks for the replies.. Got it compiling. ;quote:Original post by SiCrane  tangentz: your code is outdated and inflexible.Ah, that''s good to know.  For new code that I write for thenewer compilers, I''ll definitely use the much cleaner syntax. Kami no Itte ga ore ni zettai naru! ;  Okay, different problem I ran into, but dont want to start a new thread.How do I declare a templated class a friend in VC 7.0.Please say I can do it in this version. I know vc 6 dont support it. ;  Did you try somethine like:template <typename T> class MyFriend;class SomeClass {  template <typename T> friend class MyFriend;}; 