dimanche 1 mars 2020

How does an iterator works internally in C++?

I am unable to understand how iterator works exactly in C++. As I read in some blogs that iterator does not contain address. If it does not contain address then how exactly are we incrementing it like it++ or ++it.

Lets take an example of a vector iterator.

vector<int> ::iterator it;
for(it=vec.begin(); it!=vec.end(); it++)
{
    // do something
}

if iterator is not a pointer containing an address then what exactly is it++ doing. What is it storing. How is it working internally. How is iterator exactly pointing to the elements of a vector?

Aucun commentaire:

Enregistrer un commentaire