#include <memory>
class Base {
public:
Base() = default;
virtual ~Base() = default;
virtual void run() = 0;
};
class Derived1: public Base {
public:
Derived1() = default;
virtual ~Derived1() = default;
void run() {}
};
class Derived2: public Base {
public:
Derived2() = default;
virtual ~Derived2() = default;
void run() {}
};
void doSomething(std::shared_ptr<Base> ptr) {
ptr->run();
}
int main() {
doSomething(std::make_shared<Derived1>());
doSomething(std::make_shared<Derived2>());
}
I2luY2x1ZGUgPG1lbW9yeT4KCmNsYXNzIEJhc2UgewogICAgcHVibGljOgogICAgICAgIEJhc2UoKSA9IGRlZmF1bHQ7CiAgICAgICAgdmlydHVhbCB+QmFzZSgpID0gZGVmYXVsdDsKICAgICAgICB2aXJ0dWFsIHZvaWQgcnVuKCkgPSAwOwp9OwoKY2xhc3MgRGVyaXZlZDE6IHB1YmxpYyBCYXNlIHsKICAgIHB1YmxpYzoKICAgICAgICBEZXJpdmVkMSgpID0gZGVmYXVsdDsKICAgICAgICB2aXJ0dWFsIH5EZXJpdmVkMSgpID0gZGVmYXVsdDsKICAgICAgICB2b2lkIHJ1bigpIHt9Cn07CgpjbGFzcyBEZXJpdmVkMjogcHVibGljIEJhc2UgewogICAgcHVibGljOgogICAgICAgIERlcml2ZWQyKCkgPSBkZWZhdWx0OwogICAgICAgIHZpcnR1YWwgfkRlcml2ZWQyKCkgPSBkZWZhdWx0OwogICAgICAgIHZvaWQgcnVuKCkge30KfTsKCnZvaWQgZG9Tb21ldGhpbmcoc3RkOjpzaGFyZWRfcHRyPEJhc2U+IHB0cikgewogICAgcHRyLT5ydW4oKTsKfQoKaW50IG1haW4oKSB7CiAgICBkb1NvbWV0aGluZyhzdGQ6Om1ha2Vfc2hhcmVkPERlcml2ZWQxPigpKTsKICAgIGRvU29tZXRoaW5nKHN0ZDo6bWFrZV9zaGFyZWQ8RGVyaXZlZDI+KCkpOwp9Cg==