Vector index to iterator
-
Hi, i am trying to point my vector iterator to some vector index like this: std::vector::iterator* it= myVec[i]; But it fails: no known conversion for argument 1 from ‘Data’ to ‘std::vector::iterator Please help :)
std::vector<int>::iterator it = myVec.begin() + i;
«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
-
std::vector<int>::iterator it = myVec.begin() + i;
«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
-
Thank you, but can you explain why my version does not work? Are the types not compatible? I can access vector elements by dereferencing iterators, does it not work the other way around?
It doesn't work because it is wrong.
Quote:
std::vector::iterator* it= myVec[i];
You are trying to assign a value (not an address) to an iterator. Please note, even
std::vector::iterator* it= &myVec[i];
Would NOT WORK, because iterators are not exactly pointers.
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?! -- C++ FQA Lite