§14/2(强调我的)
A template-declaration can appear only as a namespace scope or class scope declaration. In a function template declaration, the last component of the declarator-id shall not be a template-id. [ Note: That last component may be an identifier, an operator-function-id, a conversion-function-id, or a literal-operator-id. In a class template declaration, if the class name is a simple-template-id, the declaration declares a class template partial specialization (14.5.5). —end note ]
请注意,declarator-id 在语法 (N4140) 中定义,如下所示:
声明符 ID:
...选择 id 表达式
id-表达式:
不合格的 ID
合格 ID
不合格 ID:
标识符
操作符函数 ID
转换函数ID
文字运算符 ID
~类名
~ decltype-specifier
模板 ID
鉴于在函数模板声明中,declarator-id 是一个标识符、operator-function-id、conversion-function-id ,或者一个literal-operator-id,上面的表达式“最后一个组件”是什么意思?
最佳答案
在语法引用中,您省略了 qualified-id 的产生式,它扩展为 unqualified-id 序列,以及最后一个组件 指的是最后一个 unqualified-id。
标准告诉您 函数模板声明不能以template-id结尾 与类模板的部分特化相反
template<typename T> class A {};
template<typename T> class A<std::vector<T> > {}; // ends with simple-template-id
即使函数模板的qualified-id的某些组件可能是template-id,如
template<typename>
struct A {
void f();
};
template<typename T>
void A<T>::f() {} // cannot end with template-id
关于c++ - §14/2 中的 "last component"一词的含义是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28203734/