首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

How to test if the two data's type are the same?该怎么处理

2012-02-19 
How to test if the two datas type are the same?Hi,Igotaproblemasthetitledescribes.Ihaveseensomeone

How to test if the two data's type are the same?
Hi,  

I   got   a   problem   as   the   title   describes.  

I   have   seen   someone   do   as   the   following  

(void)(&a==&b)  

so,   if   the   expression   is   0,   you   got   a   different   type.But   i   am   confused   with   that.

[解决办法]
(void)(&a==&b)
This expression according to operater take an address, whatsoever the data type, compared bit by bit with the memory data by the memory length .

[解决办法]
You can use "typeid() ",a simple function
[解决办法]
char ch1;
char ch2;
int i;
then typeid(ch1)==typeid(ch2),and typeid(i)=\=typeid(ch1)
[解决办法]
#include <typeinfo.h>

const type_info& t1 = typeid( cha1);
const type_info& t2 = typeid( cha2);

bool b = strcmp(t1.raw_name(),t2.raw_name())

热点排行