I read that this code A a( A() ); was interpreted by the compiler as a function declaration while here I clearly see that A() is a function that returns an object. How can it be something else that the construction of a A object ?
I've just read entirely the Function declaration page of cppreference : https://en.cppreference.com/w/cpp/language/function and I don't see anywhere that the parameters list can look like that A().
I don't understand how The most vexing parse can be valid C++.
A()isn't a function declaration by itself, but it can be the type of a function.For instance, suppose I declare the following function:
A makeAnA();. The type ofmakeAnAisA(): A function that takes no arguments and returns anA.Quoting cppreference on functions:
So a function that has zero parameters, returns an
A, and isn'tnoexcepthas the typeA().Therefore, it's possible to interpret
A a( A() );as a function declaration. It declares thataaccepts a single, unnamed argument of typeA(), and returns anAas its result. Because it's possible to interpret this as a function declaration, it is required by the standard that it is so interpreted.