Jump to content
  • Advertisement

Archived

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

Removing an element from a vector

This topic is 5305 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

I need to remove element #idx from vector v. How is this done? Like this? v.erase(&v.front()+idx); "On a long enough timeline the survival rate of everyone drops to zero" - Fight Club

Share this post


Link to post
Share on other sites
Advertisement
error C2678: binary ''+'' : no operator defined which takes a left-hand operand of type ''struct voter'' (or there is no acceptable conversion)

Share this post


Link to post
Share on other sites
quote:
Original post by emileej
I need to remove element #idx from vector v. How is this done? Like this? v.erase(&v.front()+idx);
It doesn''t work?

Share this post


Link to post
Share on other sites
Google says...
Anyway, from what I can see, really, unless your standard library is really weird, v.erase(&v.front()+idx) should work. Again, did you try it?

And, AFAIK, it is equivalent to &v.front() == v.begin() since vector iterators are pointers.

Cédric

Share this post


Link to post
Share on other sites
It should work but there appears to be some sort of detail that is missing...you may need to post some of the code.

Share this post


Link to post
Share on other sites
You can use operator [] with the std::vector too

v.erase(&v[index]);

Although you should check that the index is a valid number

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!