“typealias” is a new feature introduced in C++ 11. It is the replacement of typedef.
“using” is the keyword used in typealias.
typealias is used to give an alternate name for already exsisting data type.
We shall see how to define using typealias and also using typedef.
If you want to defind “unsigned long” to “ull”
1. using typealias you define by:
using ul = unsiged long;
2. using typedef you define by:
#define unsiged long ul;
If you can compare the redability of 1 and 2, 1 is easily readable.
using fun = void (*) (int);
One situation where typealias us useful is, typedef will not work with templates. Typealias will work with template.
template<typename T1, typename T2> using Map = std::map<T1, std::vector<T2>>;
Some more examples:
using i = int; using arr = int; // array of 50 ints using fp = void(*)(int); // pointer to function of int returning void