#include <iostream>
using namespace std;
struct A1
{
void func() { cout << "classA1::func()" << endl; }
};
struct A2
{
virtual void func() { cout << "classA2::func()" << endl; }
};
struct B1 : public A1
{
void func() { cout << "classB1::func()" << endl; }
};
struct B2 : public A2
{
void func() { cout << "classB2::func()" << endl; }
};
int main()
{
B1 b1;
B2 b2;
A1* pa1;
A2* pa2;
pa1 = &b1;
pa2 = &b2;
pa1->func(); //①
pa2->func(); //②
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IEExCnsKICB2b2lkIGZ1bmMoKSB7IGNvdXQgPDwgImNsYXNzQTE6OmZ1bmMoKSIgPDwgZW5kbDsgfQp9OwpzdHJ1Y3QgQTIKewogIHZpcnR1YWwgdm9pZCBmdW5jKCkgeyBjb3V0IDw8ICJjbGFzc0EyOjpmdW5jKCkiIDw8IGVuZGw7IH0KfTsKc3RydWN0IEIxIDogcHVibGljIEExCnsKICB2b2lkIGZ1bmMoKSB7IGNvdXQgPDwgImNsYXNzQjE6OmZ1bmMoKSIgPDwgZW5kbDsgfQp9OwpzdHJ1Y3QgQjIgOiBwdWJsaWMgQTIKewogIHZvaWQgZnVuYygpIHsgY291dCA8PCAiY2xhc3NCMjo6ZnVuYygpIiA8PCBlbmRsOyB9Cn07CmludCBtYWluKCkKewogIEIxIGIxOwogIEIyIGIyOwoKICBBMSogcGExOwogIEEyKiBwYTI7CgogIHBhMSA9ICZiMTsKICBwYTIgPSAmYjI7CgogIHBhMS0+ZnVuYygpOyAvL+KRoAogIHBhMi0+ZnVuYygpOyAvL+KRoQogIHJldHVybiAwOwp9