C ++ 11中的'typedef'和'using'有什么区别? [英] What is the difference between 'typedef' and 'using' in C++11?

查看:34
本文介绍了C ++ 11中的'typedef'和'using'有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在 C++11 中我们现在可以使用 using 来编写类型别名,例如 typedefs:

I know that in C++11 we can now use using to write type alias, like typedefs:

typedef int MyInt;

据我了解,相当于:

using MyInt = int;

新语法源于努力表达模板类型定义":

And that new syntax emerged from the effort to have a way to express "template typedef":

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

但是,对于前两个非模板示例,标准中是否还有其他细微差别?例如,typedef 在弱"类中做别名.大大地.也就是说,它不会创建新类型,而只会创建新名称(这些名称之间隐含转换).

But, with the first two non-template examples, are there any other subtle differences in the standard? For example, typedefs do aliasing in a "weak" way. That is it does not create a new type but only a new name (conversions are implicit between those names).

using 是一样的还是生成一个新的类型?有什么不同吗?

Is it the same with using or does it generate a new type? Are there any differences?

推荐答案

以下所有标准参考参考N4659:2017 年 3 月后 Kona 工作草案/C++17 DIS.

但是,对于前两个非模板示例,标准还有其他细微差别吗?

But, with the first two non-template examples, are there any other subtle differences in the standard?

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