Use std :: mem_fun_ref to wrap a member function as a unary function.
#include <algoritm> #include <functional> std::vector<A> the_vector; ... std::for_each(the_vector.begin(), the_vector.end(), std::mem_fun_ref(&A::doSomething));
You can also use std :: mem_fun if your vector contains pointers to the class and not the objects themselves.
std::vector<A*> the_vector; ... std::for_each(the_vector.begin(), the_vector.end(), std::mem_fun(&A::doSomething));
source share