fork download
  1. #include <utility>
  2. #include <iostream>
  3. #include <functional>
  4.  
  5. //──────────────────────────────────────────────────────────────────────────────
  6. using CallbackType = std::function<void(void*, int, int)>;
  7. // ──────────────────────────────────────────────────────────────────────────────
  8.  
  9. class Karbofos {
  10. CallbackType Call;
  11. public:
  12. const std::string Name = "Карбофос";
  13. void SetCallback(CallbackType C) {
  14. Call = std::move(C);
  15. }
  16. void Run() {
  17. if (Call)
  18. Call(this, 1, 20);
  19. std::cout << "- Не продам!\n";
  20. }
  21. };
  22. //──────────────────────────────────────────────────────────────────────────────
  23. class Shef {
  24. public:
  25. void Entreaty(void* c, int a, int b) {
  26. std::cout << "- " << ((Karbofos*)c)->Name
  27. << ", продай слона за "
  28. << a << "." << b << "р ?\n";
  29. }
  30. };
  31. //──────────────────────────────────────────────────────────────────────────────
  32. int main() {
  33. Karbofos K;
  34. Shef S;
  35. K.SetCallback(std::bind(
  36. &Shef::Entreaty, &S,
  37. std::placeholders::_1,
  38. std::placeholders::_2,
  39. std::placeholders::_3)
  40. );
  41. K.Run();
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0s 4244KB
stdin
Standard input is empty
stdout
- Карбофос, продай слона за 1.20р ?
- Не продам!