- [Instructor] The type def feature may be used to
provide an alias for a type name.
This can be handy in instances where a type declaration
becomes cumbersome, or it may vary on
different target systems.
This is typedef.cpp from chapter three
of the exercise files.
And you notice down here
that I create a couple of type def's,
using unsigned char and
char one points _t
and rank _t.
The _t is traditional for type def types.
It's not required by the language
but it's a good idea to do it
because then you've got an idea when you're using it,
that it's a type def.
And so down here, I just use them as integers
and when I build and run this
you see score S had five points in a rank of one.
So a simple alias like this can be convenient
and providing architecture independent types.
like I'm doing here
where I might want to use an unsigned char on, one type
of system, and something else on another type of system.
In fact, the U end types in the standard INT
library are created with type staffs,
just like these.
The type def facility can be convenient
for simplifying cumbersome type definitions
and machine dependent types,
as can be handy when dealing with complex
template types as well.
See some examples of this later in this course.