Why are type aliases useful?

From what I understand, using the keyword typedef is basically giving a valid type a different name. Such as...

 
typedef int integer;


So now the word integer can be used the same way int can.

but my question is.. how is this useful? wouldn't using the original valid type be more quicker and simple than using aliases?
In that case, yes. What about something like
typedef std::map<std::string, std::vector<int> > NameToNumbersMap;
Using NameToNumbersMap as the typename is far less cumbersome than typing out the actual type.
Last edited on
That is an overly simplified example.

See more complex cases in http://en.cppreference.com/w/cpp/language/typedef

Some reasons:
http://www.gotw.ca/gotw/046.htm
1) typedef are important for updating a software program for example

typedef float FLOAT

if you have a bunch of dataTypes of FLOAT you can change all their dataTypes by just changing the typeDef form

typedef int FLOAT

This is just for demonstrative purposes..

2) You can give a variable a more explicit name when working on different system schemes and stuff like that

Last edited on
Topic archived. No new replies allowed.