如何判断两个变量的类型是否相同?

xbt746 2006-03-14 03:07:14
在c++中有这样的函数吗?
还是通过占字节的大小来判断?
两个变量的类型可能是所用的类型,请大家指教
...全文
767 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
寻开心 2006-03-14
  • 打赏
  • 举报
回复
c/c++ 当中类型不是固有的属性
数据就是一段内存地址,可以按照任何属性来解释的

如果两个数据的内存大小一样,可以解释成相同的类型,也可以解释成不同的类型

没有必须的定义
逸学堂 2006-03-14
  • 打赏
  • 举报
回复
typeid使用必须开启运行时刻识别,开启GR

方法使用如下
#include <typeinfo.h>
int i;
int j;

cout << typeid(i).name == typeid(j) << endl;
healer_kx 2006-03-14
  • 打赏
  • 举报
回复
boost::is_same<T1, T2>::value
ykzhujiang 2006-03-14
  • 打赏
  • 举报
回复
typeid可以做到
typeid( type-id )

typeid( expression )

The typeid operator allows the type of an object to be determined at run-time.

The result of a typeid expression is a const type_info&. The value is a reference to a type_info object that represents either the type-id or the type of the expression, depending on which form of typeid is used.
healer_kx 2006-03-14
  • 打赏
  • 举报
回复
boost::is_same<T1, T2>
BluntBlade 2006-03-14
  • 打赏
  • 举报
回复
operator typeid
healer_kx 2006-03-14
  • 打赏
  • 举报
回复
看boost里的类型识别了。

64,649

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧