Using declared variable in a range-based for-loop

It’s a syntactical issue that a range-based for loop requires a declaration of a named variable, i.e. it requires a type specifier (cf, for example, cppreference.com):

for ( range_declaration : range_expression ) loop_statement

range_declaration – a declaration of a named variable, whose type
is the type of the element of the sequence represented by
range_expression, or a reference to that type. Often uses the auto
specifier for automatic type deduction

Actually I don’t know why your question got downvoted; I find your assumption quite OK; just the C++ syntax has decided to define it in another way.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)