C ++ extern模板实例化和typedef(gcc) [英] c++ extern template instantiation and typedef (gcc)

查看:67
本文介绍了C ++ extern模板实例化和typedef(gcc)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从外部实例化模板,但是我想在实例化子句中使用typedef。我认为该示例说出了上千个单词:

I am trying to instantiate a template externaly however I would like o use a typedef in the instantiation clause. I think the example says more than thousand words:

typedef myTemplate_base<commonValue> myTemplate; //in 99% of the cases I use this so I want a shorthand
extern template class myTemplate; //wont work/compiler error class infront of typedef

上工作/编译错误类infront如果我尝试实际遇到相同的错误像这样实例化模板:

I get the same error if I try to actually instantiate the template like this:

template class myTemplate;

我知道我可以编写(extern)模板类myTemplate_base< commonValue> ,但是我认为这比较丑陋,因为我需要在3个地方而不是1个地方调整我的共同价值。

I know I can write (extern) template class myTemplate_base<commonValue> instead, however I think this is uglier, since I need to adjust my common Value in 3 places instead of one.

那我怎么办放这个,在外部声明/实例化中使用typedef?

So how do I have to put this, to use the typedef in the extern declaration/instantiation?

我在Ubunutu上使用gcc 4.6.1

I am ussing gcc 4.6.1 on Ubunutu

推荐答案

typedef-name 不能用于显式实例化。

typedef-name cannot be used in explicit instantiation.

从14.7.2 / 3起

From 14.7.2/3


如果显式实例化用于类或成员类,声明中的
修饰类型说明符应包含
simple-template-id 。如果显式实例化是针对某个函数或
成员函数的,则声明中的 unqualidid 应为
a template-id 或其中的所有模板可以推导出参数,例如
template-name operator-function-id 。 ...

If the explicit instantiation is for a class or member class, the elaborated-type-specifier in the declaration shall include a simple-template-id. If the explicit instantiation is for a function or member function, the unqualifiedid in the declaration shall be either a template-id or, where all template arguments can be deduced, a template-name or operator-function-id. ...

这篇关于C ++ extern模板实例化和typedef(gcc)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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