fork(3) download
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. struct LoggerInterface {};
  5.  
  6. std::shared_ptr<LoggerInterface> pi = std::make_shared<LoggerInterface>();
  7.  
  8. struct B {
  9. virtual void foo(int blablabla, std::shared_ptr<LoggerInterface> logger = nullptr) = 0;
  10. };
  11. struct D : B {
  12. void foo(int blablabla, std::shared_ptr<LoggerInterface> logger) override {
  13. std::cout << "foo: "<<blablabla<<" "<< logger<<std::endl;
  14. }
  15. };
  16.  
  17. struct E : B {
  18. void foo(int blablabla, std::shared_ptr<LoggerInterface> logger = pi) override {
  19. std::cout << "foo: "<<blablabla<<" "<< logger<<std::endl;
  20. }
  21. };
  22.  
  23. int main() {
  24. D d;
  25. B *b=&d;
  26. b->foo(15);
  27. //d.foo(15);
  28. E e;
  29.  
  30. e.foo(16);
  31. B *b2 = &e;
  32. b2->foo(16);
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
foo: 15 0
foo: 16 0x8d97a1c
foo: 16 0