#include <iostream>
using namespace std;
struct A { virtual ~A() {} };
struct B : public A { void put(int n) { cout << n << endl; } };
struct C : public A { void put(float f) { cout << f << endl; } };
int main() {
A *objects[2];
objects[0] = new B;
objects[1] = new C;
for (A *a : objects) {
if (B *b = dynamic_cast<B*>(a)) {
b->put(10);
}
else if (C *c = dynamic_cast<C*>(a)) {
c->put(3.14);
}
}
for (A *a : objects) {
delete a;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IEEgeyB2aXJ0dWFsIH5BKCkge30gfTsKc3RydWN0IEIgOiBwdWJsaWMgQSB7IHZvaWQgcHV0KGludCBuKSB7IGNvdXQgPDwgbiA8PCBlbmRsOyB9IH07CnN0cnVjdCBDIDogcHVibGljIEEgeyB2b2lkIHB1dChmbG9hdCBmKSB7IGNvdXQgPDwgZiA8PCBlbmRsOyB9IH07CgppbnQgbWFpbigpIHsKCUEgKm9iamVjdHNbMl07CglvYmplY3RzWzBdID0gbmV3IEI7CglvYmplY3RzWzFdID0gbmV3IEM7Cglmb3IgKEEgKmEgOiBvYmplY3RzKSB7CgkJaWYgKEIgKmIgPSBkeW5hbWljX2Nhc3Q8Qio+KGEpKSB7CgkJCWItPnB1dCgxMCk7CgkJfQoJCWVsc2UgaWYgKEMgKmMgPSBkeW5hbWljX2Nhc3Q8Qyo+KGEpKSB7CgkJCWMtPnB1dCgzLjE0KTsKCQl9Cgl9Cglmb3IgKEEgKmEgOiBvYmplY3RzKSB7CgkJZGVsZXRlIGE7Cgl9CglyZXR1cm4gMDsKfQ==