fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. typedef vector<void (*)(void)> FooVector;
  7.  
  8. void foo1()
  9. { cout << "foo1 called" << endl; }
  10.  
  11. void foo2()
  12. { cout << "foo2 called" << endl; }
  13.  
  14. void foo3()
  15. { cout << "foo3 called" << endl; }
  16.  
  17. void process(const FooVector &v)
  18. {
  19. for (size_t i = 0; i < v.size(); i++) {
  20. cout << "calling function number " << i << endl;
  21. v[i]();
  22. }
  23. }
  24.  
  25. int main()
  26. {
  27. FooVector v;
  28. v.push_back(foo1);
  29. v.push_back(foo2);
  30. v.push_back(foo3);
  31. process(v);
  32. return 0;
  33. }
Success #stdin #stdout 0.01s 2816KB
stdin
Standard input is empty
stdout
calling function number 0
foo1 called
calling function number 1
foo2 called
calling function number 2
foo3 called