C ++ 11中的'typedef'和'using'有什么区别?

本文翻译自:What is the difference between 'typedef' and 'using' in C++11?

I know that in C++11 we can now use using to write type alias, like typedef s: 我知道在C ++ 11中,我们现在可以使用using来编写类型别名,例如typedef

typedef int MyInt;

Is, from what I understand, equivalent to: 据我了解,相当于:

using MyInt = int;

And that new syntax emerged from the effort to have a way to express " template typedef ": 并且,这种新语法是通过努力表达“ template typedef ”的方式而出现的:

template< class T > using MyType = AnotherType< T, MyAllocatorType >;

But, with the first two non-template examples, are there any other subtle differences in the standard? 但是,对于前两个非模板示例,标准中是否还有其他细微差别? For example, typedef s do aliasing in a "weak" way. 例如, typedef会以“弱”方式进行别名。 That is it does not create a new type but only a new name (conversions are implicit between those names). 也就是说,它不会创建新的类型,而只会创建一个新名称(这些名称之间的转换是隐式的)。

Is it the same with using or does it generate a new type? 是否与using相同或会生成新类型? Are there any differences? 有什么区别吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值