Created
October 14, 2011 13:55
-
-
Save stevedoyle/1287180 to your computer and use it in GitHub Desktop.
Calling a member function on every item in a container using for_each and mem_fun
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for_each(foos.begin(), foos.end(), mem_fun(&Foo::doStuff)); | |
// Example ... | |
class Foo | |
{ | |
public: | |
Foo(); | |
void doStuff(); | |
}; | |
int main() | |
{ | |
vector<Foo*> foos; | |
for(int i=0; i<10; ++i) | |
foos.push_back(new Foo()); | |
for_each(foos.begin(), foos.end(), mem_fun(&Foo::doStuff)); | |
... | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment