为什么不typedef的强类型? [英] Why aren't typedefs strongly typed?
本文介绍了为什么不typedef的强类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是用于的typedef
的理由不被强类型?有没有我不能看到或者是由于向后兼容任何好处?见这个例子:
What's the reason for typedefs
not being strongly typed? Is there any benefit I can't see or is it due to backward compatibility? See this example:
typedef int Velocity;
void foo(Velocity v) {
//do anything;
}
int main() {
int i=4;
foo(i); //Should result in compile error if strongly typed.
return 0;
}
我不要求解决方法获得强类型数据类型而只是想知道为什么该标准不要求的typedef
来是强类型?
感谢您。
推荐答案
由于C不是强类型的类型定义有其起源于这种思维
Because C is not strongly typed and typedef has its origin in that thinking
的typedef只是为了方便和可读性,它不会创建一个新的类型。
typedef is just for convenience and readability, it doesn't create a new type.
这篇关于为什么不typedef的强类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文