我有這樣的代碼: 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