#include <cstdio>
class Animal
{
protected: int _generation = 0;
public: Animal() : Animal(1) {
}
public: Animal(int generation) {
_generation = generation;
}
public: virtual Animal* spawn()
{
puts("Spawn From Animal");
return new Animal(_generation + 1);
}
};
class Dog : public Animal
{
public: Dog() : Dog(1) {
}
public: Dog(int generation) {
_generation = generation;
}
public: virtual Dog* spawn()
{
puts("Spawn From Dog");
return new Dog(_generation + 1);
}
};
int main()
{
Animal* a = new Dog();
Animal* x = a->spawn();
Dog* b = new Dog();
Dog* y = b->spawn();
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KCmNsYXNzIEFuaW1hbAp7Cglwcm90ZWN0ZWQ6IGludCBfZ2VuZXJhdGlvbiA9IDA7CgkKCXB1YmxpYzogQW5pbWFsKCkgOiBBbmltYWwoMSkgewkJCgl9CgkKCXB1YmxpYzogQW5pbWFsKGludCBnZW5lcmF0aW9uKSB7CgkJX2dlbmVyYXRpb24gPSBnZW5lcmF0aW9uOwoJfQoJCglwdWJsaWM6IHZpcnR1YWwgQW5pbWFsKiBzcGF3bigpCgl7CgkJcHV0cygiU3Bhd24gRnJvbSBBbmltYWwiKTsKCQlyZXR1cm4gbmV3IEFuaW1hbChfZ2VuZXJhdGlvbiArIDEpOwoJfQp9OwoKY2xhc3MgRG9nIDogcHVibGljIEFuaW1hbAp7CglwdWJsaWM6IERvZygpIDogRG9nKDEpIHsJCQoJfQoJCglwdWJsaWM6IERvZyhpbnQgZ2VuZXJhdGlvbikgewoJCV9nZW5lcmF0aW9uID0gZ2VuZXJhdGlvbjsKCX0KCglwdWJsaWM6IHZpcnR1YWwgRG9nKiBzcGF3bigpCgl7CgkJcHV0cygiU3Bhd24gRnJvbSBEb2ciKTsKCQlyZXR1cm4gbmV3IERvZyhfZ2VuZXJhdGlvbiArIDEpOwoJfQp9OwoKaW50IG1haW4oKQp7CglBbmltYWwqIGEgPSBuZXcgRG9nKCk7CglBbmltYWwqIHggPSBhLT5zcGF3bigpOwoKCURvZyogYiA9IG5ldyBEb2coKTsKCURvZyogeSA9IGItPnNwYXduKCk7CgoJcmV0dXJuIDA7Cn0=