I have this code:
void BaseOBJ::update(BaseOBJ* surround[3][3]) { forces[0]->Apply(); //in place of for loop cout << forces[0]->GetStrength() << endl; //forces is an std::vector of Force* }void BaseOBJ::AddForce(float str, int newdir, int lifet, float lifelength) {
Force newforce; newforce.Init(draw, str, newdir, lifet, lifelength); forces.insert(forces.end(), &newforce); cout << forces[0]->GetStrength();}
Now, when I call AddForce and make an infinite force with a strength of one, it cout's 1. But when update is called, it just outputs 0, as if the force were no longer there.
You are storing a pointer to force in your vector but the force is function local.
You must use
newto create in on the heap.