C ++变量declation语法 [英] C++ variable declation syntax

查看:231
本文介绍了C ++变量declation语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近遇到了这个结构:
int(m);
这似乎等价于:
int m;



奇怪的是,我从来没有见过这个特殊的成语。有人可以指点我的参考,我可以阅读这个规范,或只是直接解释?

解决方案



$ b

这不是一个成语。它只是一对冗余的括号。



有时,类似的多余括号可用于解决C ++声明中的歧义,例如

  int a(int()); 

它声明一个函数可以变成

  int a((int())); 

相当于

  int a = int(); 

并定义一个变量。但这不是你在你的情况下。


I recently came across this construct: int(m); which seems to be equivalent to: int m;

Oddly, I have never seen this particular idiom before. Can someone point me to a reference where I can read the spec on this, or just explain directly? Does this also work in straight C?

Thanks, ConfusedDeveloper

解决方案

It is not an "idiom". It is just a redundant pair of parentheses. Grammatically, they can be there, but they serve no purpose.

Sometimes similar seemingly superfluous parentheses can be used to resolve ambiguity in C++ declarations, like

int a(int());

which declares a function can be turned into

int a((int()));

which is equivalent to

int a = int();

and defines a variable. But this is not exactly what you have in your case.

这篇关于C ++变量declation语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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