#include #include #include //for type_info and bad_typeid #include "grandchild.h" using namespace std; int main() { base b(10); middle m(10, 20); grandchild g(10, 20, 30); const base *const a[] = {&b, &m, &g, 0}; const size_t n = sizeof a / sizeof a[0]; for (size_t i = 0; i < n; ++i) { try { cout << "a[" << i << "]: " << typeid(*a[i]).name(); if (typeid(*a[i]) == typeid(middle)) { cout << " (middle is the most derived type)"; } } catch (const bad_typeid& b) { cout << "caught bad_typeid " << b.what(); } cout << "\n"; } return EXIT_SUCCESS; }