dear linux(or g++) user/programer with c++: my name is eric, when I use most current g++ 4.3.3 on ubuntu to test 2 simple c++ programs, one have compiler error, -------------------- // formore.cpp -- more looping with for
#include <iostream> using namespace std; const int ArSize = 16; // example of external declaration int main() { double factorials[ArSize]; factorials[1] = factorials[0] = 1.0; // int i; for (int i = 2; i < ArSize; i++) factorials[i] = i * factorials[i-1]; for (i = 0; i < ArSize; i++) cout << i << "! = " << factorials[i] << endl; return 0; } -------------------------------------------------------- e...@eric-laptop:~/Documents/c++primerplus/download/ch05$ g++ formore.cpp formore.cpp: In function int main(): formore.cpp:12: error: name lookup of i changed for ISO for scoping formore.cpp:12: note: (if you use -fpermissive G++ will accept your code) -------------------------- or even more simpler -------- #include <iostream> using namespace std; int main () { for (int i=0; i<5; i++) cout << "C++ know loops.\n"; cout << i << endl; return(0); } -------------------- e...@eric-laptop:~$ g++ try.c++ try.c++: In function int main(): try.c++:11: error: name lookup of i changed for ISO for scoping try.c++:11: note: (if you use -fpermissive G++ will accept your code) ------------------ -------------------- the other is OK --------------- // bigstep.cpp -- count as directed #include <iostream> int main() { using namespace std; cout << "Enter an integer: "; int by; cin >> by; cout << "Counting by " << by << "s:\n"; for (int i = 0; i < 100; i = i + by) cout << i << endl; return 0; } ----------------------- e...@eric-laptop:~/Documents/c++primerplus/download/ch05$ g++ bigstep.cpp e...@eric-laptop:~/Documents/c++primerplus/download/ch05$ ./a.out ------------ you can see both programs, their for loop are very similar(or the same) for (int i=0 but why first , and second programs can not compile but the third one is OK ? please advice, thanks in advance your effort and time, fs...@luxmail.com