#include <iostream>
#include <typeinfo> // for typeid()
class Base
{
virtualvoid virtFun() // required for typeid()
{}
};
class Derived1 : public Base
{};
class Derived2 : public Base
{};
void displayName(Base* pBase)
{
std::cout << "pointer to an object of: "; // display name of the class
std::cout << typeid(*pBase).name() << std::endl; // pointed to pBase
}
int main() {
Base* ptrBase = new Derived1;
displayName(ptrBase); // pointer to an object of class Derived1
ptrBase = new Derived2;
displayName(ptrBase);
system("pause");
return 0;
}