Difference between typedef and C++11 type alias

This question already has an answer here:

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

  • There is absolutely no difference between both.

    If you take a look at the standard :

    7.1.3 The typedef specifier [dcl.typedef ]

    A typedef-name can also be introduced by an alias-declaration. The identifier following the using keyword becomes a 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.

    7.3.3 The using declaration [namespace.udecl]

    If a using-declaration uses the keyword typename and specifies a dependent name (14.6.2), the name introduced by the using-declaration is treated as a typedef-name.


    However from this page : http://en.cppreference.com/w/cpp/language/type_alias

    It is said :

    Type aliases are similar to typedefs, however, have the advantage of working with templates.

    It is seems that this :

    // template type alias
    template<class T> using ptr = T*;
    // the name 'ptr<T>' is now an alias for pointer to T
    ptr<int> x;
    

    Is only possible with the using directive.


    And do not forget that this is a C++11 feature. Some compilers do not support it yet.


    There is no difference.

    typedef gives an alias name for the type.

    链接地址: http://www.djcxy.com/p/78640.html

    上一篇: 使用有什么区别

    下一篇: typedef和C ++ 11类型别名之间的区别