As a result of modifications in the content of a container, iterators currently accessing them may become invalid. In this video, explore this concept, along with an example.
- [Instructor] Iterators help keeping access…to containers generic,…so they're very useful for producing flexible code.…However, there's a big problem you must be aware of,…and that's iterator invalidation.…When there are changes, such as insertions…or deletions in containers that are currently…using iterators,…these iterators may become invalid.…Now, by invalid I don't mean that they…will cause a runtime error,…but rather, that the iterator is no longer guaranteed…to have access to the same element…it was referring to before the change.…
There are many well-documented rules…for iterator invalidation…in the description of each container…and its member functions.…Let's see a quick example.…Let's suppose we have a vector with seven integers,…but with growth capacity to store one more…without reallocating.…This vector is currently using an iterator…that happens to have access…to position number five at the moment.…Let's also suppose that we want…to insert a new value at position number two.…
What will happen is that the original contents…
- Why the STL is important
- Containers and iterators
- Vectors and lists
- Stacks and dequeues
- Associative containers
Skill Level Advanced
1. The Standard Template Library
2. Vectors and Lists
3. Stacks, Queues, and Deques
4. Associative Containers
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.