| | |
Help with error in using iterator in a for loop
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Hello there, I'm currently encountering a strange error which is I don't know why or could this one be possible. I have several for loops inside a function and I used the iterator outside the said loop, but I do get this error which is kinda strange.
Strange.
C++ Syntax (Toggle Plain Text)
error: name lookup of 'i' changed for new ISO 'for' scoping error: using obsolete binding at 'i'
Strange.
Last edited by jaepi; Nov 7th, 2007 at 2:24 am.
Retreat!!!
code would be helpful.
"We Americans got so tired of being thought of as dumb by the rest of the world that we went to the polls last November and removed all doubt."
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
You are trying to do something like this:
The variable i is only supposed to exist inside the for loop. The compiler is complaining about your using it outside the loop.
C++ Syntax (Toggle Plain Text)
for (int i = 0; i < 12; i++) { ... } if (i < 12) ...
Last edited by Duoas; Nov 7th, 2007 at 3:33 am.
A lot of older compilers, particularly windows compilers, let you get away with a lot of stuff.
Before local scoping was put in the standard, what do compilers do with something like
?
The most flexible answer was simply to pretend that the variable was declared at the beginning of the function.
So, to fix the code, just put
Enjoy...
Before local scoping was put in the standard, what do compilers do with something like
for (int i = ...?
The most flexible answer was simply to pretend that the variable was declared at the beginning of the function.
So, to fix the code, just put
int i; at the beginning of the function and change to loop to for (i = ....Enjoy...
Last edited by Duoas; Nov 7th, 2007 at 3:48 am.
•
•
Join Date: Dec 2006
Posts: 1,089
Reputation:
Solved Threads: 164
> I was wondering why the windows compiler (specifically win32) tolerated such kind of error
past tense is correct; it does not any more.
microsoft c++ 6 was released prior to the the adoption of c++98; and behaved like c as far as for loops were concerned.
microsoft c++ 7 ( released 2003) provided c++98 conformance for this; but the default was backward compatibility with the earlier version. conformance had to be turned on explicitly ( /Zc compiler switch ).
microsoft c++ 8 ( released 2005) made c++98 conformance the default; but you can explicitly turn it off (again, with the /Zc compiler switch ).
typical microsoft; they haven't got to where they are without being pragmatic. microsoft's implementation of the c++ compiler is very good. stroustrup gave a talk on c++0x at the computer science club of waterloo university a couple of months back. here is an interesting extract from the question and answer session which followed:
the entire lecture can be downloaded from http://csclub.uwaterloo.ca/media/C++...0Overview.html
past tense is correct; it does not any more.
microsoft c++ 6 was released prior to the the adoption of c++98; and behaved like c as far as for loops were concerned.
microsoft c++ 7 ( released 2003) provided c++98 conformance for this; but the default was backward compatibility with the earlier version. conformance had to be turned on explicitly ( /Zc compiler switch ).
microsoft c++ 8 ( released 2005) made c++98 conformance the default; but you can explicitly turn it off (again, with the /Zc compiler switch ).
typical microsoft; they haven't got to where they are without being pragmatic. microsoft's implementation of the c++ compiler is very good. stroustrup gave a talk on c++0x at the computer science club of waterloo university a couple of months back. here is an interesting extract from the question and answer session which followed:
•
•
•
•
Q: What’s your opinion about the Microsoft implementation of C++?
A: Microsoft’s implementation is the the best out there, they conform to the standards pretty well and the code generated is also good. GNU gcc is also good. Though, they want you to use their “Managed C++” called C++/CLI which is totally unportable. Apple does the same with their version of C++ which is Objective C/C++ and and so does GNU. They all play this game of trying to get users just to use their product and not switch to their competitors products.
Last edited by vijayan121; Nov 7th, 2007 at 11:12 am.
![]() |
Similar Threads
- WinXP stop fatal error - C000021a (Windows NT / 2000 / XP)
- Why aren't my for loops executing? (C#)
- finding the point where a loop begins (C)
- Scanning an inputted array of words, and separating each word into a new array? (C)
- Quick Help (Java)
- Help (Windows NT / 2000 / XP)
- Deitel's "C++ How To Program" exercise 2.18 (C++)
- streams? (C)
- how many of you use 1.5? (Java)
Other Threads in the C++ Forum
- Previous Thread: Help with dynamic_cast & array of pointers
- Next Thread: Help with Fibonacci Numbers Greater than 16 digits
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






