partial template specialization and duplicate symbols

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux