#include <iostream>
#include <vector>
using namespace std;
class base {
public:
virtual void foo() = 0;
};
class d1: public base {
public:
virtual void foo() {
cout << "d1" << endl;
}
};
class d2: public base {
public:
virtual void foo() {
cout << "d2" << endl;
}
};
int main() {
std::vector<base*> v;
v.push_back(new d1());
v.push_back(new d2());
for(auto b: v) {
b->foo();
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY2xhc3MgYmFzZSB7CnB1YmxpYzoKCXZpcnR1YWwgdm9pZCBmb28oKSA9IDA7Cn07CgpjbGFzcyBkMTogcHVibGljIGJhc2UgewpwdWJsaWM6Cgl2aXJ0dWFsIHZvaWQgZm9vKCkgewoJCWNvdXQgPDwgImQxIiA8PCBlbmRsOwoJfQp9OwoKY2xhc3MgZDI6IHB1YmxpYyBiYXNlIHsKcHVibGljOgoJdmlydHVhbCB2b2lkIGZvbygpIHsKCQljb3V0IDw8ICJkMiIgPDwgZW5kbDsKCX0KfTsKCmludCBtYWluKCkgewoJc3RkOjp2ZWN0b3I8YmFzZSo+IHY7Cgl2LnB1c2hfYmFjayhuZXcgZDEoKSk7Cgl2LnB1c2hfYmFjayhuZXcgZDIoKSk7Cglmb3IoYXV0byBiOiB2KSB7CgkJYi0+Zm9vKCk7Cgl9CglyZXR1cm4gMDsKfQ==