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.

Python Recommendations:

C++ & C++11 Recommendations:

If you didn't find what you were looking, then do suggest us in the comments below. We will be more than happy to add that.

Subscribe with us to join 1500+ Python & C++ developers, to get more Tips &  Tutorials like this.