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())