您的位置:首页 > 其它

typeid typeinfo

2016-02-27 17:04 253 查看
#include<iostream>

using namespace std;

//typeid用于运行时类型识别

#include<typeinfo>

class A{

public:
virtual void F(){}

};

class B:public A{};

class C:public B{};

class DVD:public A{};

int main()

{
A *p1 = new A,*p2 = new B,*p3 = new C,*p4 = new DVD,*p5 = new B;
cout<<typeid(A).name()<<endl;
cout<<typeid(C).name()<<endl;
cout<<typeid(*p2).name()<<endl;
cout<<typeid(*p3).name()<<endl;

cout<<(typeid(*p2) == typeid(*p5))<<endl;
cout<<typeid(*p2).before(typeid(*p3))<<endl;
const type_info& t = typeid(*p4);
cout<<t.name()<<endl;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: