使用extern的显式实例化声明 [英] Explicit instantiation declaration with extern

查看:196
本文介绍了使用extern的显式实例化声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C ++标准草案n3485中阅读14.7.2,它说:


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: externopt template declaration

There 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆