#include #include #include #include using namespace std; class Base { }; class Derived : public Base { }; int main() { int integer = 1; float real32 = 3.14; int *ptr_integer = &integer; cout << "type of integer = " << typeid(integer).name() << endl; cout << "type of real32 = " << typeid(real32).name() << endl; cout << "type of ptr_integer = " << typeid(ptr_integer).name() << endl; const std::type_info& r1 = typeid(cout << integer); cout << endl; cout << "'cout<< integer' has type : " << r1.name() << endl; const std::type_info& r2 = typeid( printf("%f\n", real32) ); cout << "'printf(\"%f\\n\", real32)' has type : " << r2.name() << endl; Base b; Derived d; cout << "type of b = " << typeid(b).name() << endl; cout << "type of d = " << typeid(d).name() << endl; Base *p = (Base *) &b; cout << "type of p = " << typeid(p).name() << endl; Base *q = (Base *) &d; cout << "type of q = " << typeid(q).name() << endl; cout << "type of *q = " << typeid(*q).name() << endl; if (typeid(p) == typeid(q)) { cout << "p and q are the same" << endl; } if (typeid(*p) == typeid(*q)) { cout << "*p and *q are the same" << endl; } else { cout << "*p and *q are different" << endl; } return 0; }