partial template specialization and duplicate symbols

Wesley Smith wesley.hoke@gmail.com
Thu Sep 25 22:02:00 GMT 2008


Hi,
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;}

template<>
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?

thanks,
wes



More information about the Gcc-help mailing list