Saturday, March 2, 2013
[c++] Another C++ pointer problem
Particle* particlePtr = new Particle(p0);
P.push_back(*particlePtr);
BreakableSpringForce2Particle* force2Ptr1 = new BreakableSpringForce2Particle(psb.PS.getParticlePtr(currIdx-1), particlePtr, &psb.PS, SPRING_BREAK_THRESHOLD);
psb.PS.F.push_back(force2Ptr1);
BreakableSpringForce2Particle* force2Ptr2 = new BreakableSpringForce2Particle(psb.PS.getParticlePtr(i*latitude), particlePtr, &psb.PS, SPRING_BREAK_THRESHOLD);
psb.PS.F.push_back(force2Ptr2);
// when force2Ptr2 update the particle through its ‘particlePtr’, it will writes to the corresponding particle in the P deque and overrides the changes done by force2Ptr1 previously.
// as if force2Ptr1 and force2Ptr2 maintain their own copy of the particle as well as can have change propogate to the particle on the P
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment