使用extern的显式实例化声明 [英] Explicit instantiation declaration with extern
问题描述
2显式实例化的语法是:
explicit-instantiation:
extern
模板声明
是显式实例化的两种形式:显式实例化定义和显式实例化声明。 显式实例化声明以
extern
关键字开头。
看到一个模板声明和定义总是放在一个标题中,我从来没有看到在模板上的 extern
声明。
为什么实例化关注 extern
?
它告诉编译器不要在这个TU中实例化该模板。
请注意,如果您希望代码实际链接,则应在一个TU中实例化( extern
位)。
I am reading 14.7.2 in C++ Standard draft n3485 and it says:
2 The syntax for explicit instantiation is: explicit-instantiation:
extern
opt template declarationThere are two forms of explicit instantiation: an explicit instantiation definition and an explicit instantiation declaration. An explicit instantiation declaration begins with the
extern
keyword.
Seeing that a template declaration and definition is always put in a header, I have never seen a declaration with extern
on a template. What exactly does that bolded sentence mean?
Also why would an instantiation care about extern
?
It tells the compiler not to instantiate that template in this TU.
Note that it should be instantiated in one TU (without the extern
bit), if you want your code to actually link.
这篇关于使用extern的显式实例化声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!