Possible Duplicate:
Why is it an error to use an empty set of brackets to call a constructor with no arguments?
I have seen the C++ FQA entries about nested constructor calls and bracing and always wondered how C++ parsers resolve two and why it isn't possible for parsers to resolve it.
So I get why foo xxx();
is ambiguous. but what makes then foo x(bar());
ambiguous, as it is clearly no forward-declaration. (i.e.: there should be a grammar that can successfully detect this).
Could someone explain the limitations and ambiguity in that part of the C++ grammar?
foo x(bar());
This could be either:
1) A declaration for a variable called x
whose value is a default-constructed bar
. This is the same as foo x = bar();
.
2) A declaration for a function called x
that returns foo
and takes a single parameter -- a function that returns a bar
and takes no parameters. This is the same as foo x(bar (void));
The C++ FQA is a pile of garbage. Ignore it.
As for foo x(bar())
, it is as ambiguous as foo x()
, except the type of x
also takes an argument, which is a function. Add a pointer here and you'll see what I mean.
foo (*x)();
foo (*x)(bar(*)());
Even the idea of allowing this is beyond silly, but nobody can change it now.
(I have a sneaking suspicion that this grammar is a tad off, but I'm sure someone will correct me).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With