Simplifying the use of struct types with typedef
All of the considerations we explored for enumerations equally apply to structures. We will go through each of them as they apply to structures.
Before we examine the use of typedef
with structures, we must first complete the picture of using structures. In the previous chapter, we used structures by first defining them and then separately declaring variables of that type, as follows:
// First define a structured type.
struct Card { Face face; Suit suit; ... };
// Then declare variables of that type.
struct Card c1 , c2 , c3 , c4 , c5;
In the preceding code fragment, we have defined one type, struct Card
. In a separate statement, five variables of that type are declared – c1
, c2
, c3
, c4
, and c5
.
Another way to achieve the same result is to both define the structured type and declare variables...