Hi. As far as I know, typedef is used to assign an alias for a structure or type of data, am I wrong? Is there something more to know about Typedef?
You are right. A typedef is nothing more than a new name for a type, in that sense, it is an alias. And, it really is just a new name for a type, not a new type in and of itself. It serves the purpose of shortening names to make the code more readable, and to associate types as nested in a class declaration (see STL containers for examples). Typedefs are especially useful in generic programming and template meta-programming, because the names of the types tend to get very long (with many template arguments). They are also useful in template meta-programming to declare the results of meta-functions. But still, typedefs are just an alias for a type. In fact, this is what they are now referred to as in the new C++ standard, as type aliases, with a new syntax:
typedef std::size_t size_type; //old syntax (still valid in C++11, of course) using size_type = std::size_t; //new syntax. template <typename T> using vect_type = std::vector<T>; //new syntax allows template aliases too.
thanks Mikael. I always find your explanations easy to understand :icon_cheesygrin: