相关疑难解决方法(0)

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

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

typedef int MyInt;
Run Code Online (Sandbox Code Playgroud)

从我的理解,相当于:

using MyInt = int;
Run Code Online (Sandbox Code Playgroud)

这种新语法来自于努力表达" template typedef":

template< class T > using MyType = AnotherType< T, MyAllocatorType >;
Run Code Online (Sandbox Code Playgroud)

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

它是否与using生成新类型相同或是否生成新类型?有什么不同吗?

c++ typedef using-declaration c++11

833
推荐指数
8
解决办法
25万
查看次数

标签 统计

c++ ×1

c++11 ×1

typedef ×1

using-declaration ×1