Peter Dimov [SMTP:pdimov@mmltd.net] wrote:
From: "hicks"
Do you know why the compiler places precedence on that interpretation, rather than on one giving an instatiation of a local variable?
The C++ standard says that a function declaration takes precedence. Don't ask me why. :-) (At the risk of sliding seriously off topic...)
I suspect it's something along these lines. Given this function: void f() { int WhatIsThis(); } Is "WhatIsThis" intended to be a declaration of a function, or is it intended to be a definition and default-initialization of an int variable? A C++ compiler cannot know, so the C++Standards committee had several choices: 1) require the compiler to flag the statement as an ambiguous statement 2) require the compiler to interpret the statement as a declaration of a function 3) require the compiler to interpret the statement as a definition of an int If we examine the same syntax in C, there is no question what it is: 'WhatIsThis' is a declaration of a function. That effectively eliminates #3 from consideration because you don't want one statement to have different meanings in C and in C++. I suspect the Committee then either flipped a coin (or some used other democratic means, such as debating and voting on the issue, thumb-wrestling, or playing paper-rock-scissors) to decide between #1 and #2, or choose to adapt the well-worn guideline "When in doubt, do as the ints do" to "When in doubt, do as C does". -- Jim