我有这样的代码: std :: vector不保留数据?
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并无限力之一的实力,COUT的1.但是,当更新被调用,它只是输出0 ,仿佛这支部队已不在那里。
谢谢,工作就像一个魅力! +1 – Chris 2011-02-09 21:14:55