What is the difference between 'typedef' and 'using' in C++11?

后端 未结 7 812
误落风尘
误落风尘 2020-11-22 03:32

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

typedef int MyInt;

Is, from what I

7条回答
  •  孤独总比滥情好
    2020-11-22 04:09

    They are equivalent, from the standard (emphasis mine) (7.1.3.2):

    A typedef-name can also be introduced by an alias-declaration. The identifier following the using keyword becomes a typedef-name and the optional attribute-specifier-seq following the identifier appertains to that typedef-name. It has the same semantics as if it were introduced by the typedef specifier. In particular, it does not define a new type and it shall not appear in the type-id.

提交回复
热议问题