【发布时间】:2011-02-09 21:10:42
【问题描述】:
我有这个代码:
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();
}
现在,当我调用 AddForce 并产生一个强度为 1 的无限力时,它 cout 为 1。但是当调用 update 时,它只输出 0,就好像该力不再存在一样。
【问题讨论】: