![]() |
Scoping in for loop
Al salamo Alykom
And hi.. Thank you for reading my topic ------------------------------ After building this code: Code:
#include<iostream>i read that the problem means my compiler does not support this aspect of the ANSI standard... what is meant by that and how can i make my compiler support or not ?! **** Build of configuration Debug for project Linux_Xp_Learning **** make all Building file: ../scoped_for_loop.cpp Invoking: GCC C++ Compiler g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"scoped_for_loop.d" -MT"scoped_for_loop.d" -o"scoped_for_loop.o" "../scoped_for_loop.cpp" ../scoped_for_loop.cpp: In function ‘int main()’: ../scoped_for_loop.cpp:19: error: name lookup of ‘i’ changed for ISO ‘for’ scoping ../scoped_for_loop.cpp:19: note: (if you use ‘-fpermissive’ G++ will accept your code) make: *** [scoped_for_loop.o] Error 1 |
Re: Scoping in for loop
That is not ansi standard. If you originally wrote that using VC++ 6.0 compiler it worked because that was a non-standard c++ compiler. Microsoft has since changed their ways and made vc++ 2010 much more ansi standard compliant.
>>how can i make my compiler support or not Your compiler IS supporting ansi standard -- it was the code you posted that was not ansi standard compliant, not the compiler. |
Re: Scoping in for loop
One way to make your code correct is to declare variable i outside and above the loop, very much linke C programs do
Code:
int main() |
| All times are GMT +5.5. The time now is 21:36. |