Sunday 16 October 2016

What is type aliasing in C++?





I am reading C++ 11 wikipedia page about new features and did not understand this part about type aliasing:
https://en.wikipedia.org/wiki/C%2B%2B11#Template_aliases




The using syntax can be also used as type aliasing in C++11:



typedef void (*FunctionType)(double); // Old style
using FunctionType = void (*)(double); // New introduced syntax




What is type aliasing and what is it used for?



Answer



The typedef keyword is used to create a new name for an existing type---that is, a type alias. Every type alias that can be formed using typedef can also be formed using the new alias-declaration syntax that starts with using. A type alias declared using an alias-declaration has exactly the same effect as one declared using typedef.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...