so i got an undefined reference error when using template explicit instantiation with full template class specialization, but the question is, partial template class specialization goes well without error.
code shows as below, do anyone know why? what's the difference between full specialization and partial specialization in this situation?
Thanks in advance.
// t.h
#include <iostream>
using namespace std;
template <typename T1, typename T2>
class A {
public:
void foo();
};
// t2.cpp
#include "t.h"
template<typename T1>
class A<T1, int> {
public:
void foo() {
cout << "T1, int" << endl;
}
};
template<>
class A<int, int> {
public:
void foo() {
cout << "int, int" << endl;
}
};
template class A<float, int>;
template class A<int, int>;
// t.cpp
#include "t.h"
int main() {
A<float, int> a;
a.foo(); // no error
A<int, int> a1;
a1.foo(); // undefined reference error, why?
return 0;
}
the compile commands are g++ t.cpp t2.cpp -o t
with gcc 4.8.5.