typedef类型检查? [英] typedef type checking?

查看:498
本文介绍了typedef类型检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让g ++对typedef进行类型检查?是否可以?即

How do I get g++ to make type checks on typedefs? Is it possible? i.e.

typedef int T1;
typedef int T2;

T1 x = 5;     //Ok with me
T2 y = x;     //Any way to get an error or a warning here?

我不能使用C ++ 0x功能(我不知道他们是否可以做。)

I can't use C++0x features (I don't know whether they can do this.)

编辑:我想要的是这样的:

What I want is something like this:

typedef int BallID;
typedef int BatID;

BatID x = 10;
map<BatID, Bat*> m;
m.insert(make_pair(x, bigbat));        //OK
BallID y = 15;
m.insert(make_pair(y, smallbat));     //Give me a warning at least plz

这太多了吗?

推荐答案

使用强类型: http://www.boost.org/doc/libs/release/boost/strong_typedef.hpp

这篇关于typedef类型检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆