🧠 Understanding typedef vs using in Modern C++

Jaewon ShinJaewon Shin
2 min read

When learning C++, you’ll often com across two different ways to create type aliases: typedef and using. They serve the same purpose — to give a new name to an existing type — but there are important differences that make using the preferred choice in modern C++.

✅ What Do They Do?

Both typedef and using create an alias for an existing type:

typedef int MyInt; // Old way (C-style)
using MyInt = int; // Modern way (C++11 and later)

Now you can write:

MyInt x = 5;

🆚 What's the Difference?

Featuretypedefusing
Syntaxtypedef OldType NewName;using NewName = OldType;
ReadabilityCan be harder to readEasier and more intuitive
Template support❌ Not supported✅ Fully supported
Introduced inC / Early C++C++11

💡 Why Prefer using?

The biggest reason to prefer using is template support. For example:

// This doesn't work with typedef
//typedef std::map<std::string, T> MyMap<T>; ❌

template <typename T>
using MyMap = std::map<std::string, T>; //✅ works perfectly

This makes using much more flexible and powerful when writing generic code.

🏗️ Inside Structs or Classes

Both typedef and using can be used inside structs:

struct A{
    typedef int OldWay;
    using NewWay = int;
}
A::OldWay a = 1;
A::NewWay b = 2;

They behave the same here — but again, using is cleaner and easier to understand.

🧾 Summary

using is a modern and more reasonable alternative to typedef. It’s especially useful in template programming and has become the standard way to create type aliases in modern C++ (C++11 and above). If you’re learning C++ today, start with using.

0
Subscribe to my newsletter

Read articles from Jaewon Shin directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Jaewon Shin
Jaewon Shin