I have a class that looks like this.
class A { public: void doSomething(); }
I have an array of these classes. I want to call doSomething() on each item in the array. What’s the easiest way to do this using the algorithms header?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use std::mem_fun_ref to wrap the member function as a unary function.
You can also use std::mem_fun if your vector contains pointers to the class, rather than the objects themselves.