jueves, enero 28, 2010

C++: How to obtain the name of a class in C++ from a pointer

How to obtain the name of a class in C++ from a pointer:

#include
#include

...
// test any pointer
X * ptr;
...
cout << "requested type is " << typeid(*ptr).name() << endl;
...