如何让g ++在typedefs上进行类型检查?可能吗?即typedef类型检查?
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特性的(我不知道他们是否能够做到这一点。)
编辑:我想是这样的:
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
这太难问了吗?
我几乎可以肯定,这是一个DUP,但我无法找到原来的。 – 2011-02-23 18:11:13
没有'typedef',尽管它的名字,没有定义一个新的类型,它只是为现有的类型创建一个别名。 – sbi 2011-02-23 18:19:03