#include <iostream>
class Base
{
public:
virtual void whoAmI()
{
std::cout << "\nI'm base\n" ;
}
};
class Derived : public Base
{
};
class SecondDerivative : public Derived
{
public:
virtual void whoAmI()
{
std::cout << "\nI'm Second derivative\n" ;
}
};
int main()
{
SecondDerivative SD;
Base* b = &SD;
b->whoAmI();
Derived d;
b = &d;
b->whoAmI();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgogCmNsYXNzIEJhc2UKewpwdWJsaWM6CiAgICB2aXJ0dWFsIHZvaWQgd2hvQW1JKCkKICAgIHsKICAgICAgICBzdGQ6OmNvdXQgPDwgIlxuSSdtIGJhc2VcbiIgOyAgICAgCiAgICB9ICAgICAgIAp9OwogCmNsYXNzIERlcml2ZWQgOiBwdWJsaWMgQmFzZQp7Cn07CiAKIApjbGFzcyBTZWNvbmREZXJpdmF0aXZlIDogcHVibGljIERlcml2ZWQKewpwdWJsaWM6CiAgICB2aXJ0dWFsIHZvaWQgd2hvQW1JKCkKICAgIHsKICAgICAgICBzdGQ6OmNvdXQgPDwgIlxuSSdtIFNlY29uZCBkZXJpdmF0aXZlXG4iIDsgICAgIAogICAgfSAgICAgICAKfTsKIAppbnQgbWFpbigpCnsKICAgIFNlY29uZERlcml2YXRpdmUgU0Q7CiAgICBCYXNlKiBiID0gJlNEOwogICAgYi0+d2hvQW1JKCk7CiAgICAKICAgIERlcml2ZWQgZDsKICAgIGIgPSAmZDsKICAgIGItPndob0FtSSgpOwogICAgcmV0dXJuIDA7ICAgICAKfQ==