#include<iostream>
using namespace std;
class A
{
public:
virtual void doSomething()
{
std::cout<<"\nIn A::doSomething()";
}
};
class B : public A
{
public:
virtual void doSomething()
{
std::cout<<"\nIn B::doSomething()";
}
};
int main()
{
B b;
A obj;
A* a = &b;
a->doSomething();
a = &obj;
a->doSomething();
return 0;
}
ICAgICNpbmNsdWRlPGlvc3RyZWFtPgogICAgdXNpbmcgbmFtZXNwYWNlIHN0ZDsKICAgIAogICAgY2xhc3MgQQogICAgewogICAgcHVibGljOgogICAgCXZpcnR1YWwgdm9pZCBkb1NvbWV0aGluZygpCiAgICAgICAgewogICAgICAgICAgICBzdGQ6OmNvdXQ8PCJcbkluIEE6OmRvU29tZXRoaW5nKCkiOwogICAgICAgIH0KICAgIH07CiAgICAKICAgIGNsYXNzIEIgOiBwdWJsaWMgQQogICAgewogICAgcHVibGljOgogICAgCXZpcnR1YWwgdm9pZCBkb1NvbWV0aGluZygpCiAgICAgICAgewogICAgICAgICAgICBzdGQ6OmNvdXQ8PCJcbkluIEI6OmRvU29tZXRoaW5nKCkiOwogICAgICAgIH0KICAgIH07CiAgICAKCiAgICAKICAgIGludCBtYWluKCkKICAgIHsKICAgIAlCIGI7CiAgICAgICAgQSBvYmo7CiAgICAJQSogYSA9ICZiOwogICAgICAJYS0+ZG9Tb21ldGhpbmcoKTsKCiAgICAgICAgYSA9ICZvYmo7CiAgICAgICAgYS0+ZG9Tb21ldGhpbmcoKTsKCiAgICAJcmV0dXJuIDA7CiAgICB9Cgog