I''m speechless. Is there any difference between the two code snippets below? They are both supposed to do the same thing: search a string vector (ie. neighbours) for a match (ie. destination).
Code Snippet One works fine, while Code Snippet Two crashes. My bug hunt in Code Snippet Two so far tells me the problem lies in the while loop. Visual Studio 6.0 is used in this case.
// Snippet One
vector<string> neighbours = pTerritory->getNeighbours();
vector<string>::iterator iter = neighbours.begin();
while( iter!=neighbours.end() )
{
if( *iter==destination )
{
pGame->getWorld()->updateResidence( _pActor->getName(), destination );
return;
}
iter++;
}
// Snippet Two
vector<string> neighbours = pTerritory->getNeighbours();
vector<string>::iterator iter = neighbours.begin();
while( ( destination!=(*iter) )&&( iter!=neighbours.end() ) )
{
iter++;
}
if( destination==(*iter) )
{
pGame->getWorld()->updateResidence( _pActor->getName(), destination );
}