This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/11585] static template member definition fails
- From: "giovannibajo at libero dot it" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 27 Feb 2005 09:03:19 -0000
- Subject: [Bug c++/11585] static template member definition fails
- References: <20030719000044.11585.mueller@kde.org>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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