#include <iostream>
using namespace std;
class Base
{
public:
virtual Base* clone() { return new Base(*this); }
virtual void identify() {std::cout << "Base\n"; }
};
class Derived : public Base
{
public:
virtual Derived* clone() override { return new Derived(*this); }
virtual void identify() override {std::cout << "Derived\n"; }
};
int main()
{
Base* foo = new Derived;
Base* bar = foo->clone();
bar->identify();
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwpjbGFzcyBCYXNlCnsKICBwdWJsaWM6CiAgICB2aXJ0dWFsIEJhc2UqIGNsb25lKCkgeyByZXR1cm4gbmV3IEJhc2UoKnRoaXMpOyB9CiAgICB2aXJ0dWFsIHZvaWQgaWRlbnRpZnkoKSB7c3RkOjpjb3V0IDw8ICJCYXNlXG4iOyB9Cn07CgpjbGFzcyBEZXJpdmVkIDogcHVibGljIEJhc2UKewogIHB1YmxpYzoKICAgIHZpcnR1YWwgRGVyaXZlZCogY2xvbmUoKSBvdmVycmlkZSB7IHJldHVybiBuZXcgRGVyaXZlZCgqdGhpcyk7IH0KICAgIHZpcnR1YWwgdm9pZCBpZGVudGlmeSgpIG92ZXJyaWRlIHtzdGQ6OmNvdXQgPDwgIkRlcml2ZWRcbiI7IH0KfTsKCmludCBtYWluKCkgCnsKCUJhc2UqIGZvbyA9IG5ldyBEZXJpdmVkOwoJQmFzZSogYmFyID0gZm9vLT5jbG9uZSgpOwoJYmFyLT5pZGVudGlmeSgpOwp9