C++ removing from list while iterating over list -


I have std :: list to bananas , and I Do anyone want to get rid of the bad guys? Is relatively an easy way to do the following pseudocode?

Exotic Child (Banana made Banana) {If (banana isbad) done. Rim (banana); }

(Creating an infection from C # and Java to C ++ has been a rocky path.)

  ban list. Rev_if (std :: mem_fun_ref (& Banana :: isBad));  

Note that you should use std :: list instead of std :: vector - however vector < / Code> Performs better in 99.9% cases, and it's easy to work with.

Edit: If you were using vectors, is not a member close to vectors, so you must use plain namespace remove_if std :

  bananaVector.erase (std :: remove_if (bananaVector.begin), bananas Whector.and (), Std :: mem_fun_ref (& Banana :: isBad)), bananas Vector.and ());  

Comments