gpt4 book ai didi

C++ 外部模板实例化和 typedef (gcc)

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:15:46 25 4
gpt4 key购买 nike

我正在尝试实例化一个外部模板,但是我想在实例化子句中使用 typedef。我认为这个例子说的不止一千个字:

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

如果我尝试像这样实际实例化模板,我会得到同样的错误:

template class myTemplate;

我知道我可以写 (extern) template class myTemplate_base<commonValue>相反,但我认为这更丑陋,因为我需要在 3 个地方而不是一个地方调整我的共同值(value)。

那么我必须如何放置才能在外部声明/实例化中使用 typedef?

我在 Ubuntu 上使用 gcc 4.6.1

最佳答案

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

从 14.7.2/3 开始

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++ 外部模板实例化和 typedef (gcc),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8569476/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com