📄 demo_type_cast_1_typeid_1.cpp
字号:
//*****************************************************
// 使用typeid操作符支持C++运行时类型信息(RTTI)特征
// 此时必须包含typeinfo.h头文件,
// 并启用RTTI编译选项Enable Run-Time Type Information
//*****************************************************
# include <iostream.h>
# include <typeinfo.h>
class Control {}; //定义一个空类
int main()
{
//Display name of type
Control ct;
if(typeid(ct)==typeid(Control))
cout<<"ct is Class Control type"<<endl;
cout<<"ct is "<<typeid(ct).name()<<" type"<<endl;
//Compare typeids and display type of expression
double counter=1.23;
if(typeid(counter)!=typeid(Control))
cout<<"counter is not "<<typeid(Control).name()<<" type"<<endl;
if(typeid(counter)!=typeid(int))
cout<<"counter is not int type"<<endl;
if(typeid(counter)==typeid(1.23))
cout<<"counter is double type"<<endl;
return 0;
}
/*
ct is class Control type
counter is not class Control type
counter is not int type
counter is double type
Press any key to continue
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -