std::vector< std::vector<coords> >::iterator iter; for(iter = characters.begin(); iter != characters.end(); iter++) { std::vector<coords>* cha = iter; // doesn't work. } // does work. std::vector<coords>* character = &characters.at(0); coords* first = &character->at(0);
And I don’t get why. Isn’t iter supposed to be a pointer to an element of the type that it’s container is supposed to ‘contain’?
Anyone willing to shed light on this?
By doesn’t work I mean:
error C2440: 'initializing' : cannot convert from 'std::_Vector_iterator<_Ty,_Alloc>' to 'std::vector<_Ty> *'
Which doesn’t make a whole lot of sense to me.
An iterator is a type that can be dereferenced like a pointer, i.e., it has an explicit
operator*()andoperator->(). It doesn’t have to be a pointer.So use
&*iterif you want to get the address of the vector.