I’m making a simple crime sim game.
Throughout it I keep doing the same thing over and over:
// vector<Drug*> drugSack;
for (unsigned int i = 0; i < this->drugSack.size(); i++)
this->sell(drugSack[i]);
Just one example. I hate having all these for loops all over the place omg QQ, anyway to do something like:
drugSack->DoForAll((void*)myCallBack);
I’m not well versed in the STL.
Time to start knowing the stl algorithms:
The idea is to create an object, called a “functor”, that can do a certain action for each of the elements in the range
drugSack.begin(), drugSack.end().This functor can be created using stl constructs like
mem_fun_ptr, resulting in a functor taking aThisClass*and aDrug*argument, and a wrapper around it that will substitute/bind theClass*forthis.