Avatar ·

What is the difference between typedef and using in C++? When to use which?

Hello, colleagues! I recently started learning C++ and came across two ways to create type aliases: the good old `typedef` and the new `using` (or alias declaration), which appeared in C++11.\n\nI understand that both seem to do the same thing. For example, I can write:\n\n```cpp\ntypedef unsigned long long ULL;\nusing ULL = unsigned long long;\n```\n\nAnd there seems to be no difference. But I've heard that `using` is cooler and is recommended in modern code. Why? What is the real difference? Are there cases where `typedef` doesn't work but `using` does? Or vice versa?\n\nI'm especially interested in complex cases: working with function pointers, templates, nested types. I tried to create an alias for a template class using `typedef` and it didn't work. Maybe I'm doing something wrong.