匿名模板类型名/类声明 [英] Anonymous template typename/class declarations

查看:68
本文介绍了匿名模板类型名/类声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇为什么允许匿名模板typename /类声明,例如:

I'm curious as to why anonymous template typename/class declarations are allowed, such as the following:

template <typename, class, typename> struct TemplateTest1 { int a; float b ; } ;
TemplateTest1 <int, int, int> tt1 ;

任何人都可以解释这些匿名类型的实际价值吗?它们影响模板结构的表达式吗?

Can anyone explain the practical value of these anonymous types? Do they affect the expression of the templated structure?

谢谢。

推荐答案

p>由匿名,我假设您的意思是未命名的模板参数

By anonymous, I assume you meant unnamed template parameter.

,您可能不需要模板参数,因此匿名使得程序员清楚地知道该参数不是在类中的任何地方使用,虽然它不是

It's allowed, because sometimes you may not need the template argument, and so making it anonymous makes it clear to programmer that the argument is not used anywhere in the class, although it's not that necessary.

类似于允许具有未命名参数的函数的方式:

It is similar to the way a function with an unnamed parameter is allowed:

void f(int) //allowed
{
}

这篇关于匿名模板类型名/类声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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