模板参数和括号 [英] Template arguments and parentheses

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

问题描述

有人可以澄清原因:


给出一个简单的模板:

Can somebody clarify why:

Given a simple template:

展开 | 选择 | 换行 | 行号

推荐答案


有人可以澄清原因:


给出一个简单的模板:
Can somebody clarify why:

Given a simple template:
展开 | 选择 | Wrap | 行号



我认为模板语法允许声明中的括号。

如果语法剂量允许它,那么你就不能使用它。对于多个参数一个接一个地指定并且你不需要括号


raghuram
I think the template syntax dosent allow a parentheses inside the declaration.
If the syntax dosent allow it then u cant use it.For multiple arguments specify one after the other and u dont need a parenthesis

raghuram



好​​吧,括号的原因是因为预处理器会尝试将多个模板参数拆分成多个参数,会导致更多编译错误:)。


标准是否说这是不正确的呢?

Well, the reason for the parentheses is because the preprocessor will try to split the multiple template arguments into multiple macro arguments, which will cause more compiler errors :).

Does the standard say this is incorrect, then?



嗯,括号的原因是因为预处理器会尝试将多个模板参数拆分为多个iple宏参数,这将导致更多编译器错误:)。
Well, the reason for the parentheses is because the preprocessor will try to split the multiple template arguments into multiple macro arguments, which will cause more compiler errors :).



预处理器与模板无关。编译器使用模板使用您指定的类型创建模板的实例(即副本)。


处理器仅影响以#开头的行。


由于编译器需要根据您指定的类型生成模板实例,因此需要指定类型。 (float)不是一种类型。它是一个类型转换,没有业务是模板参数。

The preprocessor has nothing to do with templates. It is the compiler that uses the template to create an instance of the template (that is, a copy) using the type you specify.

The processor only affects lines that begin with a #.

Since it it rthe compiler that need to generate an instance of the template based on the type you specify, then you need to specify a type. (float) is not a type. It is a type cast and has no business being a template parameter.


这篇关于模板参数和括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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