我刚刚发现GCC编译了这样的代码
template <typename A, typename B>
struct P {};
template <typename A>
template <typename B>
using Q = P<A, B>;
但我不能使用这个。
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>
实际上是一个模板?
发布于 2018-05-18 13:59:01
语法的相关部分是:
template-declaration:
template <template-parameter-list>declaration
alias-declaration:
usingidentifierattribute-specifier-seqopt=type-id;
其中一个声明可以是模板的声明,一个别名声明,或其它类型的声明中。
请注意,语法本身接受给定的代码,但上面的文本中的其他限制使其无效。
https://stackoverflow.com/questions/-100005268
复制相似问题