On Wikipedia I found this:
A a( A() );
[This] could be disambiguated either as
- a variable definition of class [
A
], taking an anonymous instance of class [A
] or
- a function declaration for a function which returns an object of type [
A
] and takes a single (unnamed) argument which is a function returning type [A
] (and taking no input).
Most programmers expect the first, but the C++ standard requires it to be interpreted as the second.
But why? If the majority of the C++ community expects the former behavior, why not make it the standard? Besides, the above syntax is consistent if you don't take into account the parsing ambiguity.
Can someone please enlighten me? Why does the standard make this a requirement?
T (*)()
? – template boya
has essentially decayed to a function pointer for use in the expressiona.f
, but the declaration itself ofa
has nothing to do with function pointers. – Lightness Races in Orbit