#include <vector>
#include <memory>
#include <iostream>
class parent{
public:
virtual int foo() = 0;
};
class child1:public parent{
virtual int foo(){ return 1; }
};
class child2:public parent{
virtual int foo(){ return 2; }
};
int main(){
std::vector<std::shared_ptr<parent>> v;
v.push_back( std::shared_ptr<parent>(new child1()));
v.push_back( std::shared_ptr<parent>(new child2()));
std::cout << "v[0]:" << v[0]->foo() << std::endl;
std::cout << "v[1]:" << v[1]->foo() << std::endl;
}
I2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPG1lbW9yeT4KI2luY2x1ZGUgPGlvc3RyZWFtPgoKY2xhc3MgcGFyZW50ewpwdWJsaWM6CiAgdmlydHVhbCBpbnQgZm9vKCkgPSAwOwp9OwpjbGFzcyBjaGlsZDE6cHVibGljIHBhcmVudHsKICB2aXJ0dWFsIGludCBmb28oKXsgcmV0dXJuIDE7IH0KfTsKY2xhc3MgY2hpbGQyOnB1YmxpYyBwYXJlbnR7CiAgdmlydHVhbCBpbnQgZm9vKCl7IHJldHVybiAyOyB9Cn07CgppbnQgbWFpbigpewpzdGQ6OnZlY3RvcjxzdGQ6OnNoYXJlZF9wdHI8cGFyZW50Pj4gdjsKdi5wdXNoX2JhY2soIHN0ZDo6c2hhcmVkX3B0cjxwYXJlbnQ+KG5ldyBjaGlsZDEoKSkpOwp2LnB1c2hfYmFjayggc3RkOjpzaGFyZWRfcHRyPHBhcmVudD4obmV3IGNoaWxkMigpKSk7CgpzdGQ6OmNvdXQgPDwgInZbMF06IiA8PCB2WzBdLT5mb28oKSA8PCBzdGQ6OmVuZGw7CnN0ZDo6Y291dCA8PCAidlsxXToiIDw8IHZbMV0tPmZvbygpIDw8IHN0ZDo6ZW5kbDsKfQo=