This is the mail archive of the gcc-bugs@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]

[Bug c++/11585] static template member definition fails


------- Additional Comments From giovannibajo at libero dot it  2005-02-27 09:03 -------
Ah no, then it is ok. When you write:

template<>
FakeList<IntFactory::TypePair> IntFactory::_types;

you are actually *declaring* a specialization of _types. A declaration is not 
a definition, so the linker complains. To mutate this into a definition you 
need to disambiguate the statement by adding an explicit constructor. For 
instance:

template<>
FakeList<IntFactory::TypePair> IntFactory::_types = 
FakeList<IntFactory::TypePair>();

In this way, the declaration of the specialization is also a definition, and 
the code compiles and links correctly.

But are you sure you want to declare a specialization of the static member in 
the first place? Probably you just want to define the static member for all 
the possible instantiations. In this case, the syntax is much easier:

template <class T>
FakeList<typename Factory<T>::TypePair> Factory<T>::_types;

and you don't need to repeat this for IntFactory, FloatFactory, 
WhateverFactory.

For more information, please consult a good book about C++ templates or ask 
somewhere else (comp.lang.c++.moderated, for instance).




-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11585


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