首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >模板别名上下文中的模板<>语法是什么?

模板别名上下文中的模板<>语法是什么?
EN

Stack Overflow用户
提问于 2018-05-18 04:11:29
回答 1查看 0关注 0票数 0

我刚刚发现GCC编译了这样的代码

代码语言:javascript
复制
template <typename A, typename B>
struct P {};

template <typename A>
template <typename B>
using Q = P<A, B>;

但我不能使用这个。

代码语言:javascript
复制
template_template.cpp:10:5: error: ‘Q<short int>’ is not a template
     Q<short><long>{};
     ^~~~~~~~
template_template.cpp:10:20: error: invalid use of incomplete type ‘Q<short int>’
     Q<short><long>{};
                    ^
template_template.cpp:2:8: note: declaration of ‘Q<short int>’
 struct P {};

为什么编译了第一个片段?

有没有一种语法来说服编译器Q<short>实际上是一个模板?

EN

回答 1

Stack Overflow用户

发布于 2018-05-18 13:59:01

语法的相关部分是:

template-declaration:

    template <template-parameter-list>declaration

alias-declaration:

    usingidentifierattribute-specifier-seqopt=type-id;

其中一个声明可以是模板的声明,一个别名声明,或其它类型的声明中。

请注意,语法本身接受给定的代码,但上面的文本中的其他限制使其无效。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100005268

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档