We can declare anonymous struct
inside for
loop as below (g++):
for(struct { bool OK = true; } s; s.OK; s.OK = false)
std::cout << "Hello, world!\n";
But, this code results in compilation error in MSVC as:
source_file.cpp(7): error C2332: 'struct': missing tag name
source_file.cpp(7): error C2062: type 'bool' unexpected
source_file.cpp(7): error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
How to fix it?
Version:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community>cl
Microsoft (R) C/C++ Optimizing Compiler Version 19.14.26430 for x86
Copyright (C) Microsoft Corporation. All rights reserved.