fork(2) download
  1. #include <string>
  2. #include <vector>
  3. #include <functional>
  4.  
  5. struct Task
  6. {
  7. std::string Name;
  8.  
  9. std::vector<Task*> *Subtasks;
  10. std::function<void(std::string const &)> Job;
  11.  
  12. Task() {}
  13. Task(std::string const &arg_0) { Name = arg_0; }
  14. Task(std::string const &arg_0, std::vector<Task*> *arg_1) { Name = arg_0; Subtasks = arg_1; }
  15. Task(std::string const &arg_0, std::function<void(std::string const &)> arg_1)
  16. { Name = arg_0; Job = arg_1; }
  17.  
  18. ~Task() { for (auto tItem : *Subtasks) { delete tItem; } }
  19. };
  20.  
  21. class Console
  22. {
  23. private:
  24. std::vector<Task*> Routine;
  25.  
  26. public:
  27. ~Console() { for (auto tItem : Routine) { delete tItem; } } //I thought that this is not needed but Valgrind thinks otherwise, strangely the deconstructors of the Tasks are not called, I guess.
  28.  
  29. void add(Task *arg_0) { Routine.push_back(arg_0); }
  30.  
  31. void foo()
  32. {
  33. Task *tTask = new Task();
  34. //Task *tTask = new Task("Name");
  35. //Task *tTask = new Task("Name", [this](std::string const &arg_0){ ; });
  36. add(tTask);
  37. }
  38. };
  39.  
  40. int main()
  41. {
  42. Console _Console;
  43. _Console.foo();
  44. }
Runtime error #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
Standard output is empty