fork(1) download
  1. #include <iostream>
  2.  
  3. class Worker
  4. {
  5. public:
  6. virtual ~Worker() = default;
  7. virtual void work() const = 0;
  8. };
  9.  
  10. class Employer
  11. {
  12. public:
  13. void askForWork(Worker const &w)
  14. {
  15. w.work();
  16. }
  17. };
  18.  
  19. int main() {
  20. Employer e;
  21.  
  22. typedef struct : Worker {
  23. void work() const override
  24. {
  25. std::cout << "I'm working\n";
  26. }
  27. } LocalWorkerT;
  28.  
  29. struct : Worker {
  30. void work() const override
  31. {
  32. std::cout << "I'm working too\n";
  33. }
  34. } LocalWorker;
  35.  
  36. e.askForWork(LocalWorkerT {});
  37. e.askForWork(LocalWorker);
  38. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
I'm working
I'm working too