#include <iostream>
class Base
{
public:
Base() { std::cout << "Base defCtor" << std::endl; }
Base(const Base& rhs) { std::cout << "Base copyCotr" << std::endl; }
virtual Base* clone() { return new Base(*this); }
};
class Derived : public Base
{
public:
Derived() { std::cout << "Derived defCtor" << std::endl; }
Derived(const Derived& rhs) : Base(rhs)
{ std::cout << "Derived copyCotr" << std::endl; }
virtual Derived* clone() { return new Derived(*this); }
};
int main()
{
Base *bp = new Derived;
Base *bq = bp->clone();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKY2xhc3MgQmFzZQp7CnB1YmxpYzoKICBCYXNlKCkgICAgICAgICAgICAgICAgeyBzdGQ6OmNvdXQgPDwgIkJhc2UgZGVmQ3RvciIgIDw8IHN0ZDo6ZW5kbDsgfQogIEJhc2UoY29uc3QgQmFzZSYgcmhzKSB7IHN0ZDo6Y291dCA8PCAiQmFzZSBjb3B5Q290ciIgPDwgc3RkOjplbmRsOyB9CiAgdmlydHVhbCBCYXNlKiBjbG9uZSgpIHsgcmV0dXJuIG5ldyBCYXNlKCp0aGlzKTsgfQp9OwoKY2xhc3MgRGVyaXZlZCA6IHB1YmxpYyBCYXNlCnsKcHVibGljOgogIERlcml2ZWQoKSAgICAgICAgICAgICAgICAgICB7IHN0ZDo6Y291dCA8PCAiRGVyaXZlZCBkZWZDdG9yIiAgPDwgc3RkOjplbmRsOyB9CiAgRGVyaXZlZChjb25zdCBEZXJpdmVkJiByaHMpIDogQmFzZShyaHMpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHsgc3RkOjpjb3V0IDw8ICJEZXJpdmVkIGNvcHlDb3RyIiA8PCBzdGQ6OmVuZGw7IH0KICB2aXJ0dWFsIERlcml2ZWQqIGNsb25lKCkgICAgeyByZXR1cm4gbmV3IERlcml2ZWQoKnRoaXMpOyB9Cn07CgppbnQgbWFpbigpCnsKICBCYXNlICpicCA9IG5ldyBEZXJpdmVkOwogIEJhc2UgKmJxID0gYnAtPmNsb25lKCk7CiAgcmV0dXJuIDA7Cn0=