Problem with iterators in a for loop

Started by
3 comments, last by legofreak211 13 years, 9 months ago
I'm trying to iterate through a list of WALL objects by using a for loop, but for some reason it doesnt register the symbol. I tried debugging it, and the program gave me a "Error CXX0017: Symbol 'iter' not found". I made sure i initiated the variable, though, so I don't see why the loop would not even start.

(What happens code-wise is it runs the for evaluation, but nothing inside the block. I've never seen anything like it before.)


list<WALL>::iterator iter;
for(list<WALL>::iterator iter=wall.begin(); iter != wall.end(); iter++ )
{
WALL temp = *iter;
if(!temp.passFromRight)
{
if((mainchar->x >= temp.x && mainchar->x - 3 < temp.x)
{
mainchar->x = (float)temp.x;
return false;
}
}
}
Advertisement
Try deleting the *.obj files and recompiling.
Quote:Original post by Gage64
Try deleting the *.obj files and recompiling.


Yeah, it still refuses to enter the for loop.
Just wondering, is there some uncompatibility issue I don't know about between lists and Win32 programs? Because all the tutorials I looked at were console applications...Don't see why it would matter though.
Here's something I missed earlier - you're re-declaring iter. You're declaring it once here:

list<WALL>::iterator iter;

and then you're declaring another variable with the same name here:

for(list<WALL>::iterator iter=wall.begin();

This variable is local to the loop (and is the one used inside the loop), so the outer variable is not modified.
Quote:Original post by Gage64
Here's something I missed earlier - you're re-declaring iter. You're declaring it once here:

list<WALL>::iterator iter;

and then you're declaring another variable with the same name here:

for(list<WALL>::iterator iter=wall.begin();

This variable is local to the loop (and is the one used inside the loop), so the outer variable is not modified.


Ohhh that makes sense...and now it's working. Thanks :)

This topic is closed to new replies.

Advertisement