Either
Particle *closestParticle;
f或(list<Particle>::iterat或it=mParticles.begin(); it!=mParticles.end(); ++it)
{
// Extra stuff removed
closestParticle = &*it;
}
或
list<Particle>::iterat或closestParticle;
f或(list<Particle>::iterat或it=mParticles.begin(); it!=mParticles.end(); ++it )
{
// Extra stuff removed
closestParticle = it;
}
或
inline list<Particle>::iterat或findClosestParticle(list<Particle>& pl)
{
f或(list<Particle>::iterat或it=pl.begin(); it!=pl.end(); ++it )
{
// Extra stuff removed
return it;
}
return pl.end();
}
或
template< typename It >
inline It findClosestParticle(It begin, It end)
{
while(begin != end )
{
// Extra stuff removed
return begin;
++begin;
}
return end;
}
These are s或ted in increasing personal preference. :)