c++ some template summary and reflection
template.h
template <typename T>class Test{
public:
T testFunction();
template <typename D>
void printD(D data);
};
template <typename T>
template <typename It>
void Test<T>::printD(It data) {
}
template.cpp
#include "template.h"
template <typename T>
T Test<T>::testFunction() {
}
//explicit instantation
template class Test<int>;
Note that the member template in the class template must be in a file, if the definition of the member function is not necessary
Then there is a control instantiation problem in C++
For example, display instantiation of class templates
template class Test<int>;
It is already instantiated in the compiler. If we tell the compiler that it has been instantiated elsewhere, we can use extern
extern template class Test<int>;