我試圖在銷燬它們時清除敵人的健康值,並且出現錯誤「沒有重載函數的實例...」與參數列表匹配如果我有以下幾點:從for循環中刪除向量中的元素 - C++
upgradeHealth.erase(inner)
這似乎只能接受這樣的事情:
upgradeHealth.erase(upgradeHealth.begin())
我所需要的元素,在內部被擦除的位置,使之與剛剛摧毀了敵人的匹配。這裏是for循環:
for (outer = 0; outer < bullets.size(); outer++)
{
for (inner = 0; inner < upgrades.size(); inner++)
{
if (upgrades[inner]->HitTest(bullets[outer]))
{
upgradeHealth[inner] -= 1;
bullets.erase(outer--);
multiplier += 0.01;
hasHit = true;
multiplierTime = 0;
cout << upgradeHealth[inner] << endl;
if (upgradeHealth[inner] == 0)
upgradeHealth.erase(inner), upgrades.erase(inner), score += 100 * multiplier;
break;
}
}
}
嘗試「upgradeHealth.begin()+內部」而不是 – Hacketo 2014-12-04 15:05:12
我曾考慮過這樣做,但掩蓋了它,但它的工作原理非常感謝你! – StallMar 2014-12-04 15:15:57