Jump to content
  • Advertisement
Sign in to follow this  
legofreak211

Problem with iterators in a for loop

This topic is 3079 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;
}
}
}

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!