fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct IService {
  5. virtual ~IService() = default;
  6. virtual void DoWork() = 0;
  7. virtual bool IsRunning() = 0;
  8. };
  9.  
  10. class ClientA : public IService {
  11. void DoWork() {
  12. std::cout << "Work in progress inside A" << endl;
  13. }
  14. bool IsRunning() {
  15. return true;
  16. }
  17. };
  18.  
  19. class ClientB : public IService {
  20. void DoWork() {
  21. std::cout << "Work in progress inside B" << endl;
  22. }
  23. bool IsRunning() {
  24. return true;
  25. }
  26. };
  27.  
  28. class Server {
  29. IService* _service;
  30. public:
  31. Server(IService* service) : _service(service)
  32. { }
  33.  
  34. void doStuff() {
  35. _service->DoWork();
  36. }
  37. };
  38.  
  39. int main() {
  40.  
  41. ClientA a;
  42. ClientB b;
  43. Server sa(&a), sb(&b);
  44. cout << "ServerA: " << endl;
  45. sa.doStuff();
  46. cout << "ServerB: " << endl;
  47. sb.doStuff();
  48. return 0;
  49. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
ServerA: 
Work in progress inside A
ServerB: 
Work in progress inside B