C++17 单独的显式方法模板实例化声明和定义
C++17 separate explicit method template instantiation declaration and definition
我目前正在使用单独的显式类模板实例化声明和显式类模板实例化定义来减少编译时间,并且它运行良好。
但是,我有一些不是模板的类,而只是类中的一些方法。
是否可以对模板方法使用相同的单独声明和定义的机制?
谢谢。
类模板(工作(:
A.HPP :
template <class T>
class A {
void f(T t);
};
// Class explicit template instantiation declaration
extern template class A<int>;
extern template class A<double>;
答.cpp:
template <class T>
void A<T>::f(T t) {
}
// Class explicit template instantiation definition
template class A<int>;
template class A<double>;
方法模板(不工作(:
b.hpp :
class B {
template <class T>
void g(T t);
};
// Method explicit template instantiation declaration
extern template method B::g<int>;
extern template method B::g<double>;
b.cpp:
template <class T>
void B::f(T t) {
}
// Method explicit template instantiation definition
template method B::g<int>;
template method B::g<double>;
是的。
b.hpp:
extern template void B::g(int);
extern template void B::g(double);
b.cpp:
template void B::g(int);
template void B::g(double);
相关文章:
- 单行类声明和实例化
- 从模板基类派生是否在派生类声明的点实例化模板
- 在实例化封闭类模板之后,我们可以声明模板类成员的部分专用化吗
- 我们可以在没有新实例化的情况下声明一个抽象方法来返回抽象超类中的子类对象吗
- 在不使用默认构造函数的情况下声明 POD 结构时,会实例化什么?
- C++17 单独的显式方法模板实例化声明和定义
- 声明基类类型的指针,但随后通过指向子类来实例化它.这是良好的编程实践吗?
- 模板函数是否以内联方式声明 constexpr,即使实例化不是 constexpr
- C 在对象实例化时如何分开声明和构造函数
- 无法在好友函数中实例化类?我没有得到在范围错误中声明
- 仅标头模板(外部模板)的显式实例化声明
- 声明无法解决"实例化后的显式专用化"错误
- gcc 中的模板显式实例化(定义和声明)
- 类模板实例化错误:未在此范围内声明类型
- 未在此作用域中声明实例化类/的作用域
- 使用显式实例化声明删除反向指针会导致 std::bad_weak_ptr 异常
- 为什么为模板实例化声明运行时多态性会导致链接器错误
- c++ 11:显式实例化声明vs显式实例化定义
- 友元声明和显式模板实例化声明
- 仅针对类的特定模板实例化声明成员函数