What are the differences between typedef and using?

advertisements

What are the differences between using

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

or

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

to provide the shorthand TypeName in the local scope?


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.