I have a similar problem moving from GCC 3.3 to GCC 4.0 but it creates an undefined symbol link error.
foo.h
template < int bonus > class foo : public bar { public: ...
private: const static RegisterItem<foo> registerItem; };
foo.cpp
template<> const RegisterItem< foo<1> > foo<1>::registerItem; template<> const RegisterItem< foo<2> > foo<2>::registerItem; template<> const RegisterItem< foo<3> > foo<3>::registerItem; template<> const RegisterItem< foo<4> > foo<4>::registerItem; template<> const RegisterItem< foo<5> > foo<5>::registerItem;
In other .cpp files I use foo<3>. The code compiles correctly but does not link.
Undefined symbols: foo<3>::registerItem
I tries moving template<> const RegisterItem< foo<X> > foo<X>::registerItem; into the header, creating some concern over multiple registrations, but this also compiled correctly but did not link with the same error.
Where should template<> const RegisterItem< foo<X> > foo<X>::registerItem; be? As a template specialization normally I would the put it in the header, but as a static and requiring there be only one ( and it worked for GCC 3.3 ) I put it in the .cpp.
How can I resolve the link error?
Thanks, Bernard Gilbert |