The following code compiles fine, but produces a linker error:
class Base {};
class Derived : public Base {};
template <typename T>
void f(const T& value);
template <>
void f(const Base& value) {
// ...
}
int main() {
Base b;
f(b);
Derived d;
f(d); // This line causes linker error.
return 0;
}
Is it possible to make this code compile and link without adding a duplicate f()
specialization for the derived class?
Thank you.
P.S I'm using clang, Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn).
P.P.S The linker error is:
Undefined symbols for architecture x86_64:
"void f<Derived>(Derived const&)", referenced from:
_main in test2-4245dc.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)