Jump to content
  • Advertisement
Sign in to follow this  
kingpinzs

issue with removing point from a list

This topic is 4222 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 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?

Share this post


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

Share this post


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

Share this post


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

Share this post


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




Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!