fork(24) download
  1. #include <memory>
  2.  
  3. class Base {
  4. public:
  5. Base() = default;
  6. virtual ~Base() = default;
  7. virtual void run() = 0;
  8. };
  9.  
  10. class Derived1: public Base {
  11. public:
  12. Derived1() = default;
  13. virtual ~Derived1() = default;
  14. void run() {}
  15. };
  16.  
  17. class Derived2: public Base {
  18. public:
  19. Derived2() = default;
  20. virtual ~Derived2() = default;
  21. void run() {}
  22. };
  23.  
  24. void doSomething(std::shared_ptr<Base> ptr) {
  25. ptr->run();
  26. }
  27.  
  28. int main() {
  29. doSomething(std::make_shared<Derived1>());
  30. doSomething(std::make_shared<Derived2>());
  31. }
  32.  
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
Standard output is empty