t1 == t2 | 如果两个对象t1和t2类型相同,则返回true;否则返回false |
t1 != t2 | 如果两个对象t1和t2类型不同,则返回true;否则返回false |
t.name() | 返回类型的C-style字符串,类型名字用系统相关的方法产生 |
t1.before(t2) | 返回指出t1是否出现在t2之前的bool值 |
#include <iostream> using namespace std; class Base {}; class Derived: public Base {}; int main() { cout << typeid(int).name() << endl << typeid(unsigned).name() << endl << typeid(long).name() << endl << typeid(unsigned long).name() << endl << typeid(char).name() << endl << typeid(unsigned char).name() << endl << typeid(float).name() << endl << typeid(double).name() << endl << typeid(string).name() << endl << typeid(Base).name() << endl << typeid(Derived).name() << endl << typeid(type_info).name() << endl; return 0; } |
在MinGW2.05下的运行结果: i j l m c h f d Ss 4Base 7Derived St9type_info Terminated with return code 0 Press any key to continue ... |
通信人家园 (https://www.txrjy.com/) | Powered by C114 |