This chapter is from the book
Usingtypedefto Substitute a Variable’s Type
C++ enables you to substitute variable types with something that you might find convenient. You use the keywordtypedeffor that. Here is an example where a programmer wants to call anunsigned inta descriptiveSTRICTLY_POSITIVE_INTEGER:
typedef unsigned int STRICTLY_POSITIVE_INTEGER; STRICTLY_POSITIVE_INTEGER numEggsInBasket = 45;
When this code is compiled, the first line tells the compiler that aSTRICTLY_POSITIVE_INTEGERis nothing but anunsigned int. At later stages, when the compiler encounters the already defined typeSTRICTLY_POSITIVE_INTEGER, it substitutes it forunsigned intand continues compilation.