Could someone please help explain it to me what does the following statement means? It will be best if you could use some examples. Thanks
An iterator can become invalid whenever a change is made to the underlying container.
Could someone please help explain it to me what does the following statement means? It will be best if you could use some examples. Thanks
An iterator can become invalid whenever a change is made to the underlying container.
An iterator is like a pointer into the container, but if you change the container and it moves things around internally so that the pointer doesn't point to where the item is, the iterator is invalid.Code:vector<int>::iterator i = v.begin(); v.push_back( 20 ); // i can't be used anymore i = v.begin(); // now i can be used again
Thanks
The statement is, without context, too general, though. Among the properties of the various containers is a description of when, exactly, iterators can become invalid.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law