#include <iostream>
#include <memory>
using namespace std;
struct Parent{
virtual void funky() = 0;
virtual ~Parent(){}
};
struct Child1 : Parent{
void funky(){cout << "Child 1";}
};
struct Child2 : Parent{
void funky(){cout << "Child 2";}
};
int main()
{
shared_ptr<Parent> ptr(new Child1());
ptr->funky();
cout << '\n';
ptr.reset(new Child2());
ptr->funky();
cout << '\n';
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWVtb3J5PgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnN0cnVjdCBQYXJlbnR7CiAgICB2aXJ0dWFsIHZvaWQgZnVua3koKSA9IDA7CiAgICB2aXJ0dWFsIH5QYXJlbnQoKXt9Cn07CgpzdHJ1Y3QgQ2hpbGQxIDogUGFyZW50ewogICAgdm9pZCBmdW5reSgpe2NvdXQgPDwgIkNoaWxkIDEiO30KfTsKCnN0cnVjdCBDaGlsZDIgOiBQYXJlbnR7CiAgICB2b2lkIGZ1bmt5KCl7Y291dCA8PCAiQ2hpbGQgMiI7fQp9OwoKaW50IG1haW4oKQp7CiAgICBzaGFyZWRfcHRyPFBhcmVudD4gcHRyKG5ldyBDaGlsZDEoKSk7CiAgICBwdHItPmZ1bmt5KCk7CiAgICBjb3V0IDw8ICdcbic7CiAgICBwdHIucmVzZXQobmV3IENoaWxkMigpKTsKICAgIHB0ci0+ZnVua3koKTsKICAgIGNvdXQgPDwgJ1xuJzsKCiAgICByZXR1cm4gMDsKfQ==