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;
}
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;
}
相关文章推荐
- 【leetcode】Array——Search a 2D Matrix(74)
- C语言:未包含头文件引起的奇怪错误
- 文本深度表示模型Word2Vec
- Android 高清加载巨图方案 拒绝压缩图片
- [Hapi.js] Up and running
- 广师Android群分享集合大分类
- Demo7:背景截取图标显示
- C++中的ostringstream、istringstream和getline()
- Bitmap图片缩放处理
- xtrabackup
- spring 整合jackson
- html5标签总结
- 【SPOJ DISUBSTR】Distinct Substrings 后缀数组
- POJ 1129 Channel Allocation DFS+四色定理
- 微信调用扫一扫的步骤
- Android项目使用兼容包(support v7)
- 005_Http之request获取客户端信息03-获取请求参数
- 【转】Linux下的多线程编程
- leetcode-98
- Solr(二)