fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #define make delete new
  4.  
  5. typedef void (*Action) (void* context);
  6.  
  7. class Loop {
  8. public:
  9. Loop(const Loop& loop):
  10. action(loop.action), context(loop.context)
  11. {
  12. action(context);
  13. }
  14.  
  15. Loop(Action a, void* context):
  16. action(a), context(context) {}
  17.  
  18. private:
  19. Loop();
  20. const Action action;
  21. void* const context;
  22. };
  23.  
  24. void count(void* c){
  25. int& i = *static_cast<int*>(c);
  26. std::cout << "step " << ++i << std::endl;
  27. }
  28.  
  29. int main() {
  30. int i = 0;
  31. Loop counter(count, &i);
  32. make std::vector<Loop>(10, counter);
  33. return 0;
  34. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
step 1
step 2
step 3
step 4
step 5
step 6
step 7
step 8
step 9
step 10