#include <iostream>
#define PRINT(x) std::cout << "typeid(" #x ").name() = \"" << typeid(x).name() << "\"" << std::endl;
class Base {
};
class Derived : public Base {
};
int main()
{
Base b, *pb;
pb = NULL;
Derived d;
PRINT(int)
PRINT(unsigned)
PRINT(long)
PRINT(unsigned long)
PRINT(char)
PRINT(unsigned char)
PRINT(float)
PRINT(double)
PRINT(std::string)
PRINT(Base)
PRINT(b)
PRINT(pb)
PRINT(Derived)
PRINT(d)
PRINT(std::type_info)
return 0;
}
结果
typeid(int).name() = "i"
typeid(unsigned).name() = "j"
typeid(long).name() = "l"
typeid(unsigned long).name() = "m"
typeid(char).name() = "c"
typeid(unsigned char).name() = "h"
typeid(float).name() = "f"
typeid(double).name() = "d"
typeid(std::string).name() = "NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE"
typeid(Base).name() = "4Base"
typeid(b).name() = "4Base"
typeid(pb).name() = "P4Base"
typeid(Derived).name() = "7Derived"
typeid(d).name() = "7Derived"
typeid(std::type_info).name() = "St9type_info"
(SAW:Game Over!)