gpt4 book ai didi

c++ - §14/2 中的单词 "last component"是什么意思?

转载 作者:搜寻专家 更新时间:2023-10-31 02:24:17 25 4
gpt4 key购买 nike

§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:
...opt id-expression

id 表达式:
不合格的 id
合格的 id

不合格的 id:
标识符
运算符函数 id
转换函数 ID
字面运算符 id
~ 类名
~ decltype-specifier
模板ID

假设在函数模板声明中,declarator-id 是标识符,operator-function-idconversion-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/

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