syntax problem

Mar 20, 2013 at 1:32pm
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...
Mar 20, 2013 at 1:37pm
it's not making an alias of anything?
Mar 20, 2013 at 1:41pm
can you plz explain me whats happening there???

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

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


Mar 20, 2013 at 1:51pm
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

Mar 20, 2013 at 1:51pm
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
Mar 20, 2013 at 1:55pm
@booradley60 (52)

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

thanks again..
Mar 20, 2013 at 1:58pm
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.