devxlogo

std::vector Iterators

std::vector Iterators

To create an iterator of a vector, you have to use a vector specialization. In the following examples, I create two vector iterators: one for the specialization vector and another for vector. Remember that iterators are strongly-typed, you cannot use an iterator of one vector specialization with another vector specialization:

 #include #include using namespace std;int main(){ vector ::iterator vi_it; vector ::iterator vs_it;}

size=3>
If you need a generic iterator, use a template:

 inline template vector ::iterator create_iterator( vector  & v){ return vector::iterator();}

size=3>

devx-admin

Share the Post: