c++ - Unnamed struct declaration inside for loop initialization statement -
in 1 of thread, had seen usage of unnamed struct
acting placeholder multiple variables of different types inside loop:
for example:
for(struct { int i; double d; char c; } obj = { 1, 2.2, 'c' }; obj.i < 10; ++obj.i) { ... }
this compiles fine g++.
standard c++03 syntax?
you can use unnamed struct anywhere can use struct - difference doesn't name can used somewhere else. can declare new type anywhere can use type, pretty much. may not particularly meaningful in places, that's matter.
i wouldn't recommend this, other in special cases, it's valid.
Comments
Post a Comment