What are the differences between typedef and using?

前端 未结 3 834
隐瞒了意图╮
隐瞒了意图╮ 2021-01-01 21:56

What are the differences between using

typedef Some::Nested::Namespace::TypeName TypeName;

or

using Some::Nested::Namespace         


        
3条回答
  •  南方客
    南方客 (楼主)
    2021-01-01 22:33

    typedef gives an alias name for the type.

    typedef Some::Nested::Namespace::TypeName TypeName;

    Once you do that, You can refer Some::Nested::Namespace::TypeName just by saying TypeName in the local namespace.


    using declaration makes the type visible in the current namespace.

    using Some::Nested::Namespace::TypeName;

    Imports the type in the current namespace.

    In this case, using the either of the above you can refer Some::Nested::Namespace::TypeName by just using TypeName in the local namespace.

提交回复
热议问题