• Advertisement

Archived

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

SDL problem

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

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.

Share this post


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

Share this post


Link to post
Share on other sites
As porthios asserted, think of a list iterator as a pointer to the templated type in the list.

Share this post


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

Share this post


Link to post
Share on other sites
Thanks for the replies, lol I didn''t realize I wrote SDL what was i thinking

Share this post


Link to post
Share on other sites
Also you should get into the habbit of preincrementing with STL wherever possible instead of post incrementing as it is more efficient with STL.

Share this post


Link to post
Share on other sites

  • Advertisement