pointer iterator interaction
Ok, this should be fairly easy for most of you (at least I hope so),
but not for me:
Let us say we have got the following elements:
std::vector<Entry> models; //Entry is a struct
std::vector<Entry>::iterator modelIterator;
In a method, I am currently writing, I need to get a pointer to an
entry in the vector.. I thought of the following:
Entry* MyObject::getNextEntry() {
Entry* tmpEntry;
if (modelIterator == models.end()) {
return NULL;
} else {
tmpEntry = modelIterator;
modelIterator++;
return tmpEntry;
}
}
Unfortunately, this does not work, I get the error message:
error: cannot convert `
__gnu_cxx::__normal_iterator<Entry*, std::vector<Entry,
std::allocator<Entry> > >' to `Entry*' in assignment
I do not really understand this: As far as I understood it, an iterator
should be a pointer to the elements of the vector, and tmpEntry in the
mehtod above is nothing else than this..
How can I get a pointer to the element to which the iterator is
currently pointing?
Thanks a lot in advance
Tim