typeid详解
来源:互联网 发布:腾牛网qq骂人软件 编辑:程序博客网 时间:2024/06/08 13:18
#include <iostream>
usingnamespace std;
classBase {};
classDerived: public Base {};
intmain()
{
Base b,*pb;
pb =NULL;
Derivedd;
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(b).name()<<endl
<<typeid(pb).name()<<endl
<< typeid(Derived).name()<< endl
<<typeid(d).name()<<endl
<< typeid(type_info).name() << endl;
return 0;
}
using
class
class
int
{
}
Base *pb2 = dynamic_cast<Base *>(new Derived);
Base &b2 = d;
Base *pb3 = &d;
cout<< typeid(pb2).name() <<endl//输出Base*
<<typeid(b2).name()<<endl//输出Base
<<typeid(pb3).name()<<endl//输出Base*
<<typeid(*pb3).name()<<endl;//输出Base
Base &b2 = d;
Base *pb3 = &d;
cout
class Base {virtual void f(){}; };
cout<< typeid(pb2).name() <<endl//输出Base*
<<typeid(b2).name()<<endl//输出Derived
<<typeid(pb3).name()<<endl//输出Base*
<<typeid(*pb3).name()<<endl;//输出Derived
cout
//采用V8环境
cout<<typeid(7.84) <<endl
<< typeid(Base*) <<endl
<< typeid(&pb3) <<endl;
cout<<
0 0
- typeid详解
- typeid详解
- typeid详解
- typeid详解
- typeid详解
- typeid详解
- typeid详解
- typeid详解
- typeid详解
- typeid详解
- typeid详解
- typeid详解
- typeid详解
- typeid详解
- typeid详解
- typeid详解
- typeid详解
- typeid详解
- dynamic_cast介绍
- dynamic_cast介绍
- RTTI、虚函数和虚基类的开销分析及…
- RTTI、虚函数和虚基类的开销分析及…
- typeid详解
- typeid详解
- 整数溢出,如何判断整数溢出
- 整数溢出,如何判断整数溢出
- typedef与define
- typedef与define
- VxWorks嵌入式系统几种常用的延时…
- VxWorks嵌入式系统几种常用的延时…
- vxWorks BSP主要文件目录的组成及…
- vxWorks BSP主要文件目录的组成及…