syntax problem

Hi,
I am a beginner in c++ and i came across some line like this..

vector<int>::iterator itr=v.begin();
\\where v is already initiated instance of vector..

i can understand that they made alias of iterator which is data member of vector
class as itr.



But i havent read in c++ so far that alias of a data member can be made.
(ex: class_name::data_member another_name)

i want to know which concept supoorts this?????
please help...
it's not making an alias of anything?
can you plz explain me whats happening there???

vector<int>::iterator =v.begin();

cant i write something like this??
vector<int>::iterator =v.begin();
the above one makes sense if i assume.....that iterator is a static member in vector class.
you've written the same thing twice? I'm not understanding what you are actually asking.
vectors can give you an iterator to make traversal 'easier'.
read this:
http://www.cprogramming.com/tutorial/stl/iterators.html


vector<int>::iterator itr =v.begin();
is the actual line.......
cant i rewrite it as
vector<int>::iterator =v.begin();?????


second one makes sense to me as iterator is static member in vector class...



thanks

vector<int>::iterator is a class that is defined within the other class vector<int>. These two classes cooperate with each other to give you some refined behavior for moving over a vector.

So when you say:
vector<int>::iterator itr=v.begin();
what you mean is create an object called itr, that is of type vector<int>::iterator. Then, the vector you want to iterate over, in this case v, exposes a way to initialize your new iterator: = v.begin();

http://www.oodesign.com/iterator-pattern.html
@booradley60 (52)

now i understood......thanks for explaining with such a detail

thanks again..
cant i rewrite it as
vector<int>::iterator =v.begin();?????


That is like the difference between:
 
double myDouble = 3.14;


and
 
double = 3.14;


clearly the second one is completely wrong.
Topic archived. No new replies allowed.