issue with removing point from a list

Started by
14 comments, last by Fukushuusha 17 years, 2 months ago
I have a list and the type is a struct I made. but when I try the following code I get error no matching function for call to `remove(std::_List_iterator<SPRITE>, std::_List_iterator<SPRITE>, POINT*, std::_List_iterator<SPRITE>)' note C:\Program Files\Dev-Cpp\include\stdio.h:183 candidates are: int remove(const char*) void Remove_list(POINT pos, RECT Src) { int nums_iter; for(list<SPRITE>::iterator i=Sprites.begin();i!=Sprites.end();++i) { Sprites.erase( remove( Sprites.begin(), Sprites.end(),&i->Pos, Sprites.end() ); } } How can I search through the list that has a my struct as the type and find a specific member and remove it?
Advertisement
you have to test the iterator to see if it equals the sprite that you want to remove. i.e.

void Remove_list(SPRITE sprite){    for(list<SPRITE>::iterator i=Sprites.begin();i!=Sprites.end();++i)    {        if (sprite == *i)            Sprites.erase( i );            }}

However, I don't know what the POINT pos and RECT Src information hold, but if they are a part of the sprite that you need to remove maybe this would work

void Remove_list(POINT pos, RECT Src){    for(list<SPRITE>::iterator i=Sprites.begin();i!=Sprites.end();++i)    {        if (pos == i->pos && Src == i->Src)            Sprites.erase( i );            }}

Also, what is int nums_iter; doing?

[Edited by - MikeTacular on January 27, 2007 10:45:47 AM]
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
Quote:Original post by MikeTacular
you have to test the iterator to see if it equals the sprite that you want to remove. i.e.

*** Source Snippet Removed ***
However, I don't know what the POINT pos and RECT Src information hold, but if they are a part of the sprite that you need to remove maybe this would work

*** Source Snippet Removed ***
Also, what is int nums_iter; doing?


I forgot to earse int nums_iter; .
second when I try that I get error
'struct SPRITE' has no member named 'pos'

So I think the issue is how to remove iteams from the list that is using a struct call SPRITE?
Oops I made a mistake in the code, okay it's fixed now. In void Remove_list(POINT pos, RECT Src) what do pos and Src hold information about? It doesn't look like you are using them at all in the function. And second remember that in my first post that I said
Quote:However, I don't know what the POINT pos and RECT Src information hold, but if they are a part of the sprite that you need to remove maybe this would work
Which means that you may have to play with the code to get it to work since I don't know what a SPRITE is defined as and what pos and Src tell you.

I noticed you didn't say that the compiler complained about Src == i->Src which suggests to me that maybe pos == i->Pos would work.

Remember that to remove something from a list, you must iterate through it (which you are doing), test the iterator and see if it is the item you want to remove (which was missing from your code), and then tell the list to erase(iterator).

Anyways, hoped that helped.

[EDIT]
I would suggest looking at these two tutorials:
Clicky 1
Clicky 2

[Edited by - MikeTacular on January 27, 2007 11:43:14 AM]
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
Quote:Original post by MikeTacular

what do pos and Src hold information about?



it is loaded from this. It holds the rect and x and y coords for the block

list<int>::iterator curr = DataList.begin();        list<LoadData::RectX>::iterator curr2 = DataList2.begin();        while(curr != DataList.end()&& curr2 !=DataList2.end())        {            // the position            PoX = *curr;            ++curr;            PoY = *curr;            ++curr;            left = curr2->left;            top =   curr2->top;            right =   curr2->right;            bottom =   curr2->bottom;            ++curr2;   Add(MakePoint(PoX,PoY),MakeRect(left,top,right, bottom));


Quote:Original post by MikeTacular

I don't know what a SPRITE is defined as and what pos and Src tell you.



SPRITE is defined here

typedef struct {    int x,y;    int width,height;    int movex,movey;    int curframe,lastframe;    int animdelay,animcount;    int scalex, scaley;    int rotation, rotaterate;    POINT Pos;    RECT Src;} SPRITE;



How do I compare the iterator with the pos?

if(paddle.Pos == *i)


I get error
no match for 'operator==' in 'paddle.SPRITE::Pos == (&i)->std::_List_iterator<_Tp>::operator* [with _Tp = SPRITE]()'

note C:\Program Files\Dev-Cpp\include\objbase.h:80 candidates are: BOOL operator==(const GUID&, const GUID&)


no matter what I try I get the simalr error
Quote:Original post by kingpinzs
How do I compare the iterator with the pos?

If the iterator is to a list<SPRITE>, which seems to be the case, you must dereference the iterator with the * operator, effectively turning it into a SPRITE. Then, you can access its members:
if(paddle.Pos == (*i).Pos)
-jouley

[Edit: vector to list]
still get the same exact error. I have been at this for a wile and this little thing is killing me. I just dont understand why I cant compare the data I put into it with the data inside the list
POINT is probably a struct and doesn't have any operator overloads. The compiler doesn't know what to do with it either.

You will have to compare the member variables of the point structures instead.

if(paddle.Pos.x == (*i).Pos.x && paddle.Pos.y == (*i).Pos.y)

Steven Yau
[Blog] [Portfolio]

Ah, I should have read more carefully. There's no '==' operator for POINTs. So, you'll have to examine both members independently:
if(paddle.Pos.x == (*i).Pos.x && paddle.Pos.y == (*i).Pos.y)


[Edit: beated]

This topic is closed to new replies.

Advertisement