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? (有什么区别吗?)
ask by Klaim translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…