vector 迭代 删除指定的元素
std::vector< Bullet * > m_vBullets; std::vector< Bullet * > m_vRemoveBulltes; if ( m_vRemoveBulltes.size() > 0 ){ for ( std::vector< Bullet * >::iterator it = m_vRemoveBulltes.begin(); it != m_vRemoveBulltes.end(); it++){ //需要删除的子弹 for (std::vector< Bullet * >::iterator it1 = m_vBullets.begin(); it != m_vBullets.end(); it1++){//总子弹 if ( *it == *it1 ){//当总子弹的和要删除的相等 removeChild(*it1);//删除子弹 m_vBullets.erase( it1 );//在总子弹数组里面删除子弹元素 it1 = m_vBullets.begin();//迭代重置..删除了子弹元素..会变成野指针.不写会报错 } } } m_vRemoveBulltes.clear();//清空需要删除的子弹数组 }