What is the difference between 'typedef' and 'using'?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
typedef and using can both create a type alias in C++, so for simple cases they seem interchangeable. The practical difference is that using has clearer syntax and supports alias templates directly, which makes it the more flexible choice in modern C++.
Neither keyword creates a brand-new type. Both simply give another name to an existing type, which is an important distinction when you think about overloads, conversions, and readability.
Simple Aliases: Both Work
For a basic alias, the two forms are equivalent:
Both IndexA and IndexB are just aliases for unsigned long.
For simple aliases, the real difference is readability. Many developers find using Name = Type; easier to read because the alias name appears on the left and the aliased type appears on the right, like a normal assignment-style declaration.
Complex Types Read Better With using
This difference becomes clearer with function pointers:
Both are valid, but using is usually easier to parse quickly.
That readability benefit scales up as the aliased type becomes more complicated. For modern code, that is one of the biggest practical arguments for preferring using.
Alias Templates Are the Big Functional Advantage
typedef cannot create an alias template directly. using can:
With typedef, you need an extra wrapper struct:
The wrapper works, but it is noisier and less direct. This is the main reason using is considered more powerful in template-heavy C++.
using Is Not Only for Type Aliases
One reason the keyword can feel confusing is that using does more than alias types. In other contexts it is also used for:
- namespace imports such as
using std::cout; - inherited constructors
- bringing base-class members into scope
But in an alias declaration, the pattern is specifically:
That syntax has a single clear meaning: create an alias.
Neither One Creates a Distinct Type
This is a common misunderstanding:
Even though the names suggest different meanings, both aliases are still just int. The compiler does not treat them as separate strong types.
So this works without conversion:
If you need real type safety, use a wrapper class or struct instead of an alias.
When typedef Still Appears
You will still see typedef in:
- older C and C++ codebases
- C headers shared with C++
- legacy documentation and interview questions
There is nothing wrong with understanding or maintaining it. But in new C++ code, using is usually preferred because it is more consistent with modern style and works better with templates.
Common Pitfalls
- Assuming
typedefandusingcreate distinct new types. - Preferring
typedefin template-heavy code where alias templates would be cleaner. - Mixing up
usingalias declarations with otherusingforms such as namespace imports. - Rewriting old
typedefstatements mechanically without checking whether readability actually improves. - Using aliases where a real wrapper type would be safer and clearer.
Summary
- '
typedefandusingboth create type aliases.' - '
usingis usually easier to read, especially for complex types.' - '
usingsupports alias templates directly, whiletypedefdoes not.' - Neither keyword creates a new strong type; both only create alternate names.
- In modern C++,
usingis usually the better default unless you are working in legacy-style code.

