SDL problem

Started by
4 comments, last by huffer59 19 years, 10 months ago
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.
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) ].
As porthios asserted, think of a list iterator as a pointer to the templated type in the list.
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]
Thanks for the replies, lol I didn''t realize I wrote SDL what was i thinking
Also you should get into the habbit of preincrementing with STL wherever possible instead of post incrementing as it is more efficient with STL.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms

This topic is closed to new replies.

Advertisement