#include <iostream>
using namespace std;
class Base
{
public:
virtual void print(){cout<<"Base virtual"<<endl;}
void nonvirt_print(){cout<<"Base"<<endl;}
};
class Derived : public Base
{
public:
virtual void print() override {cout<<"Derived virtual"<<endl;}
void nonvirt_print(){cout<<"Derived"<<endl;}
};
void f(Base **base_arr) {
base_arr[10]->nonvirt_print(); //base
base_arr[10]->print(); //derived virtual
}
int main() {
Derived *derived_arr[100];
for(int i=0;i<100;++i)
derived_arr[i] = new Derived();
f(reinterpret_cast<Base*>(derived_arr));
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY2xhc3MgQmFzZQp7CglwdWJsaWM6Cgl2aXJ0dWFsIHZvaWQgcHJpbnQoKXtjb3V0PDwiQmFzZSB2aXJ0dWFsIjw8ZW5kbDt9Cgl2b2lkIG5vbnZpcnRfcHJpbnQoKXtjb3V0PDwiQmFzZSI8PGVuZGw7fQp9OwoKY2xhc3MgRGVyaXZlZCA6IHB1YmxpYyBCYXNlCnsKCXB1YmxpYzoKCXZpcnR1YWwgdm9pZCBwcmludCgpIG92ZXJyaWRlIHtjb3V0PDwiRGVyaXZlZCB2aXJ0dWFsIjw8ZW5kbDt9IAoJdm9pZCBub252aXJ0X3ByaW50KCl7Y291dDw8IkRlcml2ZWQiPDxlbmRsO30KfTsKCnZvaWQgZihCYXNlICoqYmFzZV9hcnIpIHsKCWJhc2VfYXJyWzEwXS0+bm9udmlydF9wcmludCgpOyAvL2Jhc2UKCWJhc2VfYXJyWzEwXS0+cHJpbnQoKTsgLy9kZXJpdmVkIHZpcnR1YWwKfQoKaW50IG1haW4oKSB7CglEZXJpdmVkICpkZXJpdmVkX2FyclsxMDBdOwoJZm9yKGludCBpPTA7aTwxMDA7KytpKQoJCWRlcml2ZWRfYXJyW2ldID0gbmV3IERlcml2ZWQoKTsKCWYocmVpbnRlcnByZXRfY2FzdDxCYXNlKj4oZGVyaXZlZF9hcnIpKTsKCXJldHVybiAwOwp9