Some miscellaneous notes for c++ primer class templates. I always forget some notes that may be simpler and control instantiation

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>;

Guess you like

Origin blog.csdn.net/qq_32783703/article/details/104881540