partial template specialization and duplicate symbols

Wesley Smith
Thu Sep 25 22:02:00 GMT 2008

I'm having a linker issue with partial template specialization.  I
have a templated class

// in header A.h
//A basic example of what I have:
template<typename T>
class A{
static int func1();

template<typename T>
int A<T>::func1() {return 1;}

int A<float>::func1() {return 2;}

I'm including A.h in another header file and instantiating the
template as a member of a class:

// in B.h
class B{
   A<float> a;

Then, I have another file that includes B.h, let's call it code.cpp.
The problem is when B.cpp and code.cpp get linked into a library, the
specialized function A<float>::func1 is defined symbol-wise in both
B.o and code.o, so the linker sees duplicate symbols, which I haven't
found a way around.  Any ideas?


More information about the Gcc-help mailing list