#include <iostream>
#include <list>
using namespace std;
class T1 {
public:
virtual void f() {
cout<<"I'm f() from T1"<<endl;
}
};
class T2 {
public:
virtual void f() {
cout<<"I'm f() from T2"<<endl;
}
virtual void g() {
cout<<"I'm g() from T2"<<endl;
}
};
class T3 : public T1, public T2 {
public:
void f() {
T2::f();
T1::f();
}
};
int main() {
// your code goes here
list<T2*> l{ new T2(), new T3() };
for (auto &x : l) {
x->f();
x->g();
}
cout <<"--"<<endl;
T1* last_one = dynamic_cast<T1*>(l.back()); // last is also T1
last_one->f();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bGlzdD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNsYXNzIFQxIHsKcHVibGljOiAKICAgIHZpcnR1YWwgdm9pZCBmKCkgewogICAgCWNvdXQ8PCJJJ20gZigpIGZyb20gVDEiPDxlbmRsOyAKICAgIH0KfTsKY2xhc3MgVDIgewpwdWJsaWM6IAogICAgdmlydHVhbCB2b2lkIGYoKSB7CiAgICAJY291dDw8IkknbSBmKCkgZnJvbSBUMiI8PGVuZGw7IAogICAgfQogICB2aXJ0dWFsIHZvaWQgZygpIHsKICAgIAljb3V0PDwiSSdtIGcoKSBmcm9tIFQyIjw8ZW5kbDsgCiAgICB9Cn07CmNsYXNzIFQzIDogcHVibGljIFQxLCBwdWJsaWMgVDIgewpwdWJsaWM6IAogICAgdm9pZCBmKCkgewogICAgCVQyOjpmKCk7CiAgICAJVDE6OmYoKTsKICAgIH0KfTsKCmludCBtYWluKCkgewoJLy8geW91ciBjb2RlIGdvZXMgaGVyZQoJbGlzdDxUMio+IGx7IG5ldyBUMigpLCBuZXcgVDMoKSB9OwoJZm9yIChhdXRvICZ4IDogbCkgewoJCXgtPmYoKTsgCgkJeC0+ZygpOwoJfQoJY291dCA8PCItLSI8PGVuZGw7IAoJVDEqIGxhc3Rfb25lID0gZHluYW1pY19jYXN0PFQxKj4obC5iYWNrKCkpOyAgLy8gbGFzdCBpcyBhbHNvIFQxIAoJbGFzdF9vbmUtPmYoKTsgIAoJCglyZXR1cm4gMDsKfQ==