typedef

It can become tedious, repetitious, and, most important, error-prone to keep writing unsigned short int. You can create a synonym for an existing type by using the keyword typedef, which stands for type definition.

It is important to distinguish this from creating a new type (which you will do in Hour 7, “Basic Classes”). typedef is used by writing the keyword typedef followed by the existing type and then the new name. For example,

typedef unsigned short int USHORT

creates the new name USHORT that you can use anywhere you might have written unsigned short int. Listing 3.3 is a replay of Listing 3.2 using the type definition USHORT rather ...

Get Sams Teach Yourself C++ in 24 Hours, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.