Home > Back-end >  About the solutions of the iterator references will disable the iterator?
About the solutions of the iterator references will disable the iterator?

Time:10-22

An iterator related problems, in a loop calling the func () will be reported to the runtime errors, prompt the iterator I cross a line, but the func () to understand the reference, I just didn't I make the change, however, remove the func () can perform well, is it because of I know references lead to internal
what's the problem?
 
Bool func (const char c)
{
return true;
}

Void main ()
{
String s (" 1 ");
For (auto I=s.c the begin (); Func (* I) & amp; & S.c end ()!=I; I++);//a runtime error, the iterator I cross-border
//for (auto I=s.c the begin (); S.c end ()!=I; I++);//run normally
}

CodePudding user response:

Because you have reached the tail, and then the error it solutions for reference of course
Change

For (auto I=s.c the begin (); S.c end ()!=i& & Func (* I); I++);
  • Related