I thought one could declare several variables in a for
loop:
for (int i = 0, char* ptr = bam; i < 10; i++) { ... }
But I just found out that this is not possible. GCC gives the following error:
error: expected unqualified-id before 'char'
Is it really true that you can't declare variables of different types in a for
loop?
Best Answer
You can (but generally shouldn't) use a local struct type.
Since C++11, you can initialize the individual parts more elegantly, as long as they don't depend on a local variable:
This is just almost readable enough to really use.
C++17 addresses the problem with structured bindings: