Skip to main content
gamedev.net
🔒 Locked

SDL problem

Started by huffer59 Jun 10, 2004 at 6:10 PM 4 replies 450+ views
Original Post
huffer59
huffer59
list particleList; list::iterator i; for(i=particleList.begin(); i!=particleList.end(); i++) { updateParticle(//pointer to s_Particle structure); } The problem I have is i can''t find it anywhere how to get a pointer to the element that iterator is pointing at.
porthios
porthios
1) STL not SDL

2) If your list contains pointers to the s_Particle class, just dereference the iterator [ *i ]. If it contains just normal instances of the s_Particle class, dereference the pointer and use the address operator to pass it as a pointer [ &(*i) ].
NLDEV
NLDEV
As porthios asserted, think of a list iterator as a pointer to the templated type in the list.
leiavoia
leiavoia
list<s_Particle> particleList;
list<s_Particle>::iterator i;

for(i=particleList.begin(); i!=particleList.end(); i++)
{
updateParticle( (*i) );

}


although if i were you (and i'm not...), i'd do this instead

list<s_Particle> particleList;
list<s_Particle>::iterator i;

for(i=particleList.begin(); i!=particleList.end(); i++)
{
(*i)->Update();

}



[edited by - leiavoia on June 10, 2004 8:12:22 PM]
huffer59
huffer59
Thanks for the replies, lol I didn''t realize I wrote SDL what was i thinking
iMalc
iMalc
Also you should get into the habbit of preincrementing with STL wherever possible instead of post incrementing as it is more efficient with STL.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.