How do you remove a vector? c++ -


i have zombies project i've been given uni i'm stuck on couple of things.

how remove vector? have zombies , pill objects stored in vectors. first thought change symbol doesn't work since that's changing this:

for (int = 0; < maxpills; i++) {     //if pill coordinates = spot coordinates     if ((pills.at(i).y == sp.y) && (pills.at(i).x == sp.x))     {         pills.at(i).symbol = tunnel;    //make pill tunnel     } } 

this pill object needs removed instead. have when zombie falls down hole (sp instance of zombie class).

how can remove together?

use remove_if algorithm instead:

pills.erase(std::remove_if(pills.begin(), pills.end(), [&sp](const decltype(pills.at(0)) &p){return p.x == sp.x && p.y == sp.y;})); 

note i'm using lambda function here c++11 construct might want check whether you're allowed use in assignment first , replace functor object if you're not allowed use c++11.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -