Jump to content
  • Advertisement

Archived

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

quasar3d

iterator to pointer

This topic is 5559 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
quote:
Original post by quasar3d

Is this really the best way? It looks so ugly




Yeah it is. Iterators are ugly things.

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!