c++ - Iterator = pointer? Or what is it? -


is iterator in c++ pointer? reason ask seems nobody understands iterator is. it's "thing" or "value" say. iterator points element, position. when dereferencing it, it's looking @ iterator points to. correct analogy? please, help

the short answer is:

  • pointer kind of iterator.
  • pointer can therefore used iterator.
  • pointer has properties other iterator.

history

historically, have c pointer, , adapted c++ when c++ invented. pointer represents location in memory, therefore can used location in array.

later, in 1990s, idea called "iterator concept" introduced c++. "iterator concept" related library called stl (which later absorbed standard library) , paradigm called "generic programming". iterator concept inspired c pointer represent location in containers vector, deque , others, how c pointer represent location in array. the iterator concept engineered compatible c pointer, hence can nowadays c pointer models iterator concept.

iterator concept

a simplified way understand iterator concept that, if data type suppports list of operations , behaviours, such represent location in container, , enable kind of access element, can called iterator.

with carefull design of iterator concept, c pointer fulfill list. pointer therefore kind of iterator.

iterator concept being set of requirement on types, means can create own iterator through c++ power of data abstraction.

other properties of pointer

pointer exhibits other properties, , not related iterator concept.

a significant use of pointer express reference semantics, i.e. refer object in remote memory location. usage of pointer later considered unsafe, , causes invention of "smart pointer". comparing smart pointers , iterators, can find totally unrelated concepts.

another use of pointer refer raw memory location. unsafe application programming, essential tool microcontroller programming manipulate hardware.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -