// File: main2.C // // Testing typeinfo.h #include #include #include #include "person3.h" void typer(Person *) ; void typer (Person *ptr) { cout << typeid(*ptr).name() << endl ; if (typeid(*ptr) == typeid(Person)) { cout << "ptr is pointing to a Person" << endl ; } else if ( typeid(*ptr) == typeid(Student)) { cout << "ptr is pointing to a Student" << endl ; } else if ( typeid(*ptr) == typeid(Faculty)) { cout << "ptr is pointing to a Faculty" << endl ; } else { cout << "ptr is pointing to something else" << endl ; } } main() { Person P("James Bond", 37) ; Student S("Peppermint Patty", 7, 1, 1.2) ; Faculty F("Newt Gingrich", 53, 12) ; Person *ptr ; int n ; cout << "Pick (1-3): " ; cin >> n ; if (n == 1) { ptr = &P ; } else if (n == 2) { ptr = &S ; } else { ptr = &F ; } ptr->id() ; typer(ptr) ; }