In C++, it is possible to create synonyms that can be used instead of a type name. This is achieved by creating a typedef
declaration. This is useful in several cases, such as creating shorter or more meaningful names for a type or names for function pointers. However, typedef
declarations cannot be used with templates to create template type aliases
. An std::vector<T>
, for instance, is not a type (std::vector<int>
is a type), but a sort of family of all types that can be created when the type placeholder T
is replaced with an actual type.
In C++11, a type alias is a name for another already declared type, and an alias template is a name for another already declared template. Both of these types of aliases are introduced with a new using
syntax.