#include<iostream>
class I{
public:
virtual void f()=0;
};
enum TYPE{
TYPE_I,
};
class Base{
public:
Base(){
std::cout << "Base::Base()\n";
}
virtual ~Base(){
std::cout << "Base::~Base()\n";
}
virtual TYPE getType()=0;
int i;
};
class A : public Base, public I {
public:
A(){
std::cout << "A::A()\n";
}
virtual ~A(){
std::cout << "A::~A()\n";
}
virtual TYPE getType(){
std::cout << "A::getType()\n";
return TYPE_I;
}
virtual void f(){ std::cout << "A::f()\n"; }
};
int main(){
A *a=new A;
void *vp=a;
if(static_cast<Base*>(vp)->getType()==TYPE_I){
std::cout << "call I::f()\n";
static_cast<I*>(vp)->f();
}
std::cout << "delete a\n";
delete a;
}
I2luY2x1ZGU8aW9zdHJlYW0+CmNsYXNzIEl7CglwdWJsaWM6CgkJdmlydHVhbCB2b2lkICBmKCk9MDsKfTsKCmVudW0gVFlQRXsKCVRZUEVfSSwKfTsKCmNsYXNzIEJhc2V7CglwdWJsaWM6CgkJQmFzZSgpewoJCQlzdGQ6OmNvdXQgPDwgIkJhc2U6OkJhc2UoKVxuIjsgCgkJfQoJCQoJCXZpcnR1YWwgfkJhc2UoKXsKCQkJc3RkOjpjb3V0IDw8ICJCYXNlOjp+QmFzZSgpXG4iOyAKCQl9CgkJdmlydHVhbCBUWVBFIGdldFR5cGUoKT0wOwoJCWludCBpOwp9OwoKY2xhc3MgQSA6IHB1YmxpYyBCYXNlLCBwdWJsaWMgSSB7CglwdWJsaWM6CgkJQSgpewoJCQlzdGQ6OmNvdXQgPDwgIkE6OkEoKVxuIjsgCgkJfQoJCXZpcnR1YWwgfkEoKXsKCQkJc3RkOjpjb3V0IDw8ICJBOjp+QSgpXG4iOyAKCQl9CgkJdmlydHVhbCBUWVBFIGdldFR5cGUoKXsKCQkJIHN0ZDo6Y291dCA8PCAiQTo6Z2V0VHlwZSgpXG4iOyAKCQkJcmV0dXJuIFRZUEVfSTsKCQl9CgkJdmlydHVhbCB2b2lkICBmKCl7IHN0ZDo6Y291dCA8PCAiQT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