[Solved] Few questions about initialization and lambda in c++ [closed]


Ad 1.

You’ve been bitten by the most vexing parse. Basically, C++ grammar causes ambiguities between statements and declarations in certain cases. In such cases, the input is interpreted as a declaration. Since int i() can be interpreted as an integer variable definition, or a function declaration, it is interpreted as a declaration of parameterless function i, returning int.

Ad 2.

As for the second question, C++11 Standard §5.1.2/3 says it all:

The type of the lambda-expression (…) is a unique, unnamed non-union class type — called the closure type (…)

So, there is no way to refer to it other than using auto.

2

solved Few questions about initialization and lambda in c++ [closed]