I have a class, like this:
class Particle()
{
void CalcSomething(Super& arg){
for(unsigned long long index = 0; index < arg.NumberOfParticle(); index ++){
if(this != arg.ParticleMemoryPointer(index)){
// Do the calculations
}
}
}
}
And the following class holds the particles:
class Super()
{
const Particle* const ParticleMemoryPointer(unsigned int index)
{
std::list<Particle>::iterator iter = mParticles.begin();
std::advance(iter, index);
return &(*iter);
}
std::list<Particle> mParticles;
}
The idea being, the instance of a particle, which is calling CalcSomething needs to detect when CalcSomething is being called from the same instance of Particle as the one addressed by the index inside the function CalcSomething
. (Does that make sense? I haven't worded it very well...)
You realize the reason for this is if we are to do a calculation between two particles, we need to make sure they are different particles.
Some cout statements show the memory address returned by ParticleMemoryPointer is not the same as the this
pointer for the case when there is one item in the list. (They should be, with one item, we are doing a calculation with the same particle twice.)
I hope this is understandable.
Edit The function inside Super which calls CalcSomething:
void Super::UpdateParticles(double time_step)
{
std::list<Particle>::iterator iter = mParticles.begin();
for(unsigned long long index = 0; index < mParticles.size(); index ++){
std::advance(iter, 1);
iter->CalcSomething(*this);
}
}
Edit 2 We can't use std::vector. (We know you were thinking it!)