Help with error in using iterator in a for loop

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2006
Posts: 647
Reputation: jaepi is an unknown quantity at this point 
Solved Threads: 4
jaepi's Avatar
jaepi jaepi is offline Offline
Practically a Master Poster

Help with error in using iterator in a for loop

 
0
  #1
Nov 7th, 2007
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.

  1. error: name lookup of 'i' changed for new ISO 'for' scoping
  2. error: using obsolete binding at 'i'

Strange.
Last edited by jaepi; Nov 7th, 2007 at 2:24 am.
Retreat!!!
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,675
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 193
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso

Re: Help with error in using iterator in a for loop

 
0
  #2
Nov 7th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,951
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Help with error in using iterator in a for loop

 
1
  #3
Nov 7th, 2007
You are trying to do something like this:
  1. for (int i = 0; i < 12; i++) {
  2. ...
  3. }
  4. if (i < 12) ...
The variable i is only supposed to exist inside the for loop. The compiler is complaining about your using it outside the loop.
Last edited by Duoas; Nov 7th, 2007 at 3:33 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 647
Reputation: jaepi is an unknown quantity at this point 
Solved Threads: 4
jaepi's Avatar
jaepi jaepi is offline Offline
Practically a Master Poster

Re: Help with error in using iterator in a for loop

 
0
  #4
Nov 7th, 2007
Yep, that is exactly what the code is doing. I'm actually porting a windows code to linux. And I was wondering why did he(windows programmer) did that.
Retreat!!!
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,951
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Help with error in using iterator in a for loop

 
0
  #5
Nov 7th, 2007
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
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 647
Reputation: jaepi is an unknown quantity at this point 
Solved Threads: 4
jaepi's Avatar
jaepi jaepi is offline Offline
Practically a Master Poster

Re: Help with error in using iterator in a for loop

 
0
  #6
Nov 7th, 2007
I was wondering why the windows compiler (specifically win32) tolerated such kind of error. It'll surely work. Thanks!
Retreat!!!
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,089
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Solved Threads: 164
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: Help with error in using iterator in a for loop

 
0
  #7
Nov 7th, 2007
> 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:
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.
the entire lecture can be downloaded from http://csclub.uwaterloo.ca/media/C++...0Overview.html
Last edited by vijayan121; Nov 7th, 2007 at 11:12 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC