“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 defined “unsigned long” to “ul”
1. using typealias you define by:
using ul = unsigned long;
2. using typedef you define by:
#define unsigned long ul;
If you can compare the redability of 1 and 2, 1 is easily readable.
Another example:
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[50]; // array of 50 ints
using fp = void(*)(int); // pointer to function of int returning void