fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct ILogger {
  5. virtual ~ILogger() {}
  6. virtual void log(string m) = 0;
  7. };
  8.  
  9. class Car {
  10. ILogger* logger;
  11.  
  12. public:
  13. explicit Car(ILogger* l)
  14. : logger(l) {
  15.  
  16. }
  17.  
  18. void drive() {
  19. logger->log("driving is so good");
  20. }
  21. };
  22.  
  23. class Trailer : public Car, private ILogger {
  24. public:
  25. Trailer() : Car(this) {
  26.  
  27. }
  28.  
  29. void unpack() {
  30. log("unpacking trailer");
  31. }
  32.  
  33. void log(string m) override {
  34. // putting record in our journal
  35. cout << "[trailer journal]: " << m << endl;
  36. }
  37. };
  38.  
  39. int main() {
  40. Trailer t;
  41. t.unpack();
  42. // it's time to move
  43. t.drive();
  44.  
  45. return 0;
  46. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
[trailer journal]: unpacking trailer
[trailer journal]: driving is so good