Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ variable declation syntax

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

like image 261
ConfusedDeveloper Avatar asked Jan 18 '11 19:01

ConfusedDeveloper


1 Answers

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.

like image 170
AnT Avatar answered Sep 24 '22 20:09

AnT