建议使用显式模板实例化来减少编译时间。我想知道该怎么做。例如
// a.h
template<typename T> class A {...};
template class A<int>; // explicit template instantiation to reduce compilation time
但在每个包含 a.h 的翻译单元中,似乎都是 A<int>
将被编译。编译时间没有减少。如何使用显式模板实例化来减少编译时间?
最佳答案
在头部声明实例化:
extern template class A<int>;
并在一个源文件中定义它:
template class A<int>;
现在它只会被实例化一次,而不是在每个翻译单元中,这可能会加快速度。
关于c++ - 如何使用显式模板实例化来减少编译时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26247711/