In this article we will discuss how to iterate over a container of user defined objects and call a member function on each of the iterating element.
Suppose you have a vector of Employee class objects and you want to call a member function on each of the element in vector.

Let’s see how to do this using std::for_each,

First Create an Employee Class,

Then Create a std::vector of Employee Pointers and initialize that,

Now Iterate through all the elements in vector and call displayEmployeeInfo member function for each of the element,
Also, In the end delete all the elements using std::for_each again.