模板名称和模板ID之间的差异 [英] Difference between template name and template id

查看:185
本文介绍了模板名称和模板ID之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C ++标准


第14/2节:



模板声明,
declarator-id 应为
模板名称(即不是
template-id )。在类别
模板声明中,如果
declarator-id template-id ,则

声明声明一个类
模板部分特化。


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

Section 14/2 :

In a function template declaration, the declarator-id shall be a template-name (i.e., not a template-id). [Note: in a class template declaration, if the declarator-id is a template-id, the declaration declares a class template partial specialization.

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之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆