typedef std::vector<std::string> vecOfStr; //now the alias has been created
vecOfStr strings; //this is now the same as std::vector<std::string> strings;
strings.push_back("I was created with a typedef.");
//.............
If you use a typedef it's easier to change the type, because you only need to change the code in one position.
The size of primitive types (short, int, long, etc.) depends on the compiler and platform you're on. If you want a 32 bit unsigned integer you could use unsigned int and it might work for you but it might not work when compiled with a different compiler or when compiling for a different platform. In this case it's much better to use a typedef. Then you can write code that will work almost everywhere and all you need to change is the typedef. Fixed size integers are so useful that the C++ standard library provides a number of typedefs for you in the <cstdint> header. http://www.cplusplus.com/reference/cstdint/
Typedefs can also be used to make type(def)s shorter. Maybe you use std::vector<int>::size_type in your code. It can look a bit bloated if you have to write it over and over again. You could use a typedef typedef std::vector<int>::size_type VecIntSize; and then you could just write VecIntSize instead.
DevTK wrote:
Typedef is a keyword used to define a new type.
It doesn't create a new type. A typedef is just an alias.
The size of primitive types (short, int, long, etc.) depends on the compiler and platform you're on. If you want a 32 bit unsigned integer you could use unsigned int and it might work for you but it might not work when compiled with a different compiler or when compiling for a different platform
nice i can see it way clearer
sec im going to review it again