问题描述
C ++标准
template-name
, template-id
和 type-id
?
上面的引用是否意味着我们不能写
template< ;
void templatefunction< int>(){// ...}
误解了这一点?
模板名称是模板的名称。在您的示例中, templatefunction
是一个模板名称。
template-id 是具有模板参数列表的模板的名称。在您的示例中, templatefunction< int>
是 template-id 。 命名一个类型。 template-id 是 type-id ;
2涉及一个模板声明,它声明一个主模板。您的示例不是模板声明,而是显式特化(14.7.3 / 1)。
C++ Standard
What is the difference between a template-name
, template-id
and a type-id
?
Does the above quote mean we cannot write something like
template <>
void templatefunction<int>(){ // ...}
or have I misunderstood the point?
The template-name is the name of the template. In your example, templatefunction
is a template-name.
The template-id is the name of the template with the template arguments list. In your example, templatefunction<int>
is the template-id. A template-id names a template specialization.
A type-id names a type. A template-id is a type-id; a template-name is not (because it does not name a type; it names a template).
The text you cite from 14/2 concerns a template-declaration, which declares a primary template. Your example is not a template-declaration, it is an explicit-specialization (14.7.3/1).
这篇关于模板名称和模板ID之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!