Declaring a description without changes inside a loop initialization statement

In one of the SO threads, I saw the use of an unnamed struct , acting as a placeholder for several variables of different types within a loop:

For instance:

 for(struct { int i; double d; char c; } obj = { 1, 2.2, 'c' }; obj.i < 10; ++obj.i) { ... } 

This one compiles fine with g ++.
Is this the standard C ++ 03 syntax?

+4
source share
1 answer

You can use an unnamed structure wherever you can use a structure - the only difference is that it does not get a name that can be used elsewhere. You can declare a new type wherever you can use a type, to a large extent. In most cases, this does not really matter, but that is another matter.

I would definitely not recommend this, except in special cases, but it really is.

+2
source

Source: https://habr.com/ru/post/1481533/


All Articles