This code is not able to resolve void K::func<B>(B&)
.
struct K {
template <typename T> void func(T &t);
};
struct B {
void ok();
};
// definition
template <typename T> void K::func(T &t) { t->ok(); }
// getting: undefined reference to `void K::func<B>(B&)'
// nm says ' U void K::func<B>(B&)'
template <> void K::func<B>(B &b);
template <> void K::func(B &b);
int main() {
K k;
B b;
k.func(b);
};
Note: Several other questions at SO were related to compilation; I m stuck at linking . Please point me to duplicate if any.
UPDATE: I'm following http://en.cppreference.com/w/cpp/language/template_specialization , look for functions g1 or g2 ;
UPDATE2: fixed 'func' to 'K::func' to fix 'out of class member template definition', still K::func can't be specialized.