fork download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. // ──────────────────────────────────────────────────────────────────────────────
  5.  
  6. using CallbackType = std::function<void(void*)>;
  7.  
  8. // ──────────────────────────────────────────────────────────────────────────────
  9.  
  10. class Karbofos {
  11.  
  12. CallbackType Begin = nullptr;
  13. CallbackType End = nullptr;
  14.  
  15. public:
  16.  
  17. const std::string Name = "Карбофос";
  18.  
  19. void SetCallback(CallbackType B, CallbackType E) {
  20. Begin = B;
  21. End = E;
  22. }
  23.  
  24. void Run() {
  25. if (Begin) (Begin)(this);
  26. std::cout << "- Не отдам, слон - мой!\n";
  27. if (End) (End)(this);
  28. }
  29.  
  30. };
  31.  
  32. // ──────────────────────────────────────────────────────────────────────────────
  33.  
  34. void Shef(void* i) {
  35. std::cout << "- Стой, живодер " << ((Karbofos*)(i))->Name << "!\n";
  36. }
  37.  
  38. // ──────────────────────────────────────────────────────────────────────────────
  39.  
  40. void Kollega(void* i) {
  41. std::cout << "- " << ((Karbofos*)(i))->Name << ", ты немец и контрабандист!\n";
  42. }
  43.  
  44. // ──────────────────────────────────────────────────────────────────────────────
  45.  
  46. int main() {
  47. Karbofos Object;
  48. //CallbackType S = Shef;
  49. //CallbackType K = Kollega;
  50. Object.SetCallback(Shef,Kollega);
  51. Object.Run();
  52. return 0;
  53. }
Success #stdin #stdout 0s 4480KB
stdin
Standard input is empty
stdout
- Стой, живодер Карбофос!
- Не отдам, слон - мой!
- Карбофос, ты немец и контрабандист!