PRB: Variable Scope in for-statement Extends Beyond LoopLast reviewed: July 24, 1997Article ID: Q167748 |
The information in this article applies to:
SYMPTOMSIf you declare the same variable in two different for-statements, the following error may appear:
Test.cpp(4) : error C2374: 'i' : redefinition; multiple initialization CAUSEThe scope of a variable declared in the initialization part of a "for" loop is given local scope, as if it had been declared immediately prior to the for-statement.
RESOLUTIONCompile with /Za, Disable Language Extensions. To select this option in Developer Studio, select Project, Settings, and then click the C/C++ Tab. Change the Category to Customize and select Disable Language Extensions.
MORE INFORMATION
/* Compile Options Needed to compile without error: /Za */ /* test.cpp */ void main() { for (int i=0; i<10; i++) ; for (int i=0; i<15; i++) ; } |
Keywords : CPPLngIss
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |