C++ To call member function in for_each for items in the member container
问题 If I have a class (that mimic some of STL's container) like this: class Elem { public: void prepare(); // do something on *this // ... }; class Selector { public: typedef vector<Elem *> container_type; typedef container_type::iterator iterator; iterator begin() { return cont_.begin(); } iterator end() { return cont_.end(); } void check_all(); private: prepare_elem(Elem *p); // do something on 'p' container_type cont_; }; If I want to call prepare() for all elements in 'cont_', I could make