Archived

This topic is now archived and is closed to further replies.

quasar3d

iterator to pointer

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites