View previous topic - View next topic |
Author |
Message |
XMark Guitar playin' black mage
Joined: 30 May 2002 Posts: 870 Location: New Westminster, BC, Canada
|
Posted: Tue Nov 25, 2003 12:32 am Post subject: Erasing in a vector |
[quote] |
|
Having problems with this code:
Code: |
void Map::deleteobject(int *currentobj)
{
if (entity.size() > 1)
entity.erase(&entity[*currentobj]);
if (*currentobj > entity.size() - 1)
*currentobj = entity.size() - 1;
}
|
Now, the funny thing is this worked perfectly when I was using DJGPP but now I'm using Dev-C++/MingW and it has some strange problem with it. I get this error message:
In member function 'void Map::deleteobject(int*)
no matching function for call to 'std::vector<Mapent,
(Mapent is the name of the class that holds the entities on the map.)
What's the problem? Does MingW have a different Erase method for vectors or something? _________________ Mark Hall
Abstract Productions
I PLAYS THE MUSIC THAT MAKES THE PEOPLES FALL DOWN!
|
|
Back to top |
|
|
XMark Guitar playin' black mage
Joined: 30 May 2002 Posts: 870 Location: New Westminster, BC, Canada
|
Posted: Tue Nov 25, 2003 1:20 am Post subject: |
[quote] |
|
AAAAAAAGH! Iterators. Figured the answer out.
It's a strange effect. Any time I have a coding problem that's been bugging me and I just can't figure out what to do, all I have to do is post it here and the answer magically comes to me. And, strangely enough, I don't think the answers would come if I didn't post... _________________ Mark Hall
Abstract Productions
I PLAYS THE MUSIC THAT MAKES THE PEOPLES FALL DOWN!
|
|
Back to top |
|
|
grenideer Wandering Minstrel
Joined: 28 May 2002 Posts: 149
|
Posted: Tue Nov 25, 2003 1:42 am Post subject: |
[quote] |
|
the easiest way to do this is:
entity.erase(entity.begin()+index);
...unless you already have the iterator of what you want to erase.
anyway, many times the answer doesn't come easily to you unless you fully understand the question, and asking for help forces you to think about what you want to know. the same thing happens to me a lot. _________________ Diver Down
|
|
Back to top |
|
|
LeoDraco Demon Hunter
Joined: 24 Jun 2003 Posts: 584 Location: Riverside, South Cali
|
Posted: Tue Nov 25, 2003 2:31 am Post subject: |
[quote] |
|
While it is really only useful if you have some modicum of an idea of what you're looking for, The SGI STL Programmers Guide is practically the definitive resource for all things STL. (With the standard disclaimer that there are things in the SGI STL that aren't in all variants of STL; SGI is usually quite good about labeling those items accordingly.) The nice thing about it is that it does have the standard interface to common STL objects. Which means that if you ever have a problem with something, you can look it up there. _________________ "...LeoDraco is a pompus git..." -- Mandrake
|
|
Back to top |
|
|
*XMark Guest
|
Posted: Tue Nov 25, 2003 5:28 am Post subject: |
[quote] |
|
grenideer wrote: | the easiest way to do this is:
entity.erase(entity.begin()+index);
...unless you already have the iterator of what you want to erase.
anyway, many times the answer doesn't come easily to you unless you fully understand the question, and asking for help forces you to think about what you want to know. the same thing happens to me a lot. |
Yeah, I just used an iterator and advanced it to the right index before calling the erase, but since I don't use an iterator for anything else, your way is better. Thanks! :)
|
|
Back to top |
|
|