怎样避免编译器把对象声明当作函数声明
解决办法么。。括号去掉。Test test;即可。如果是模板怕indeterminate value就T t = T();----------------------实际上关于歧义的描述在8.2。。ISO C++11 8.21 The ambiguity arising from the similarity between a function-style cast and a declaration mentioned in 6.8 can also occur in the context of a declaration. In that context, the choice is between a function declaration with a redundant set of parentheses around a parameter name and an object declaration with a function-style cast as the initializer. Just as for the ambiguities mentioned in 6.8, the resolution is to consider any construct that could possibly be a declaration a declaration. “the resolution is to consider any construct that could possibly be a declaration a declaration.”
■网友
给 @Sunchy321补充一下,C++11标准中6.8节有此表述。 【怎样避免编译器把对象声明当作函数声明】 
在C++语法中表达式语句和声明存在二义性。如果一个表达式语句的最左子表达式是函数式显示转换(就是本题中构造函数的写法),则无法将其和以左括号开始的声明(即参数表)区分。在这种情况下认为这是声明。为了消除二义性,必须检查整个语句来决定是表达式语句还是声明。下面的例子中前三个是表达式,后四个为声明。
推荐阅读
- 聪明人养花,这3种“花”怎样也要养一盆,每年能省不少医药费
- 互联网怎样解决“家政服务上门速度慢”的问题
- 怎样看待从1月8号起,QQ钱包开始提现收费
- 银行it人怎样转型
- 汽车|冬天怎样让车内温度快速升高?座椅加热的最佳使用方式二,外循环的作用总结
- 怎样进入通信行业
- 怎样评价扶他柠檬茶的小说《云养汉》的结尾
- 都更新|高中物理:高考做题陷阱总结!这些易错点赶紧避免吧!
- 怎样成为一名合格的Python程序员?
- 怎样评价华为、诺基亚、中兴中标中国移动高端路由交换设备扩容集采
