iterator to pointer
How to convert an iterator into a pointer?
In visual c++ you can just do:
std::vectoriterator i;
int *p = i;
but this doesn't work in mingw.
How can I do that in mingw? (which I suppose will be the correct way)
I can do this:
int *p = &(*i);
but that looks so ugly.
My Site
[edited by - Quasar3D on July 28, 2003 2:12:36 PM]
int *p = &*i;
This will:
* Crash if i is not dereferenceable (such as vec.begin() on an empty vector)
* Not work for vector<bool>s
How appropriate. You fight like a cow.
This will:
* Crash if i is not dereferenceable (such as vec.begin() on an empty vector)
* Not work for vector<bool>s
How appropriate. You fight like a cow.
quote:Original post by Sneftel
int *p = &*i;
This will:
* Crash if i is not dereferenceable (such as vec.begin() on an empty vector)
* Not work for vectors
How appropriate. You fight like a cow.
of course, but my program will crash anyway if I try to access an item of an empty vector, and I am not using bools, so
Is this really the best way? It looks so ugly
My Site
[edited by - Quasar3D on July 28, 2003 2:26:09 PM]
quote:Original post by quasar3d
Is this really the best way? It looks so ugly
Yeah it is. Iterators are ugly things.
iterators are beautiful things. Screwing with an iterator/container to get a pointer is an ugly thing. Only ever do it if you need to interface with a C library without support for iterators.
How appropriate. You fight like a cow.
How appropriate. You fight like a cow.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement