A typedef declaration lets you define your own identifiers that can be used in place of type specifiers such as int, float, and double. A typedef declaration does not reserve storage. The names you define using typedef are not new data types, but synonyms for the data types or combinations of data types they represent.
The name space for a typedef name is the same as other identifiers. When an object is defined using a typedef identifier, the properties of the defined object are exactly the same as if the object were defined by explicitly listing the data type associated with the identifier.
typedef vector4double vdt;
vdt v1;
typedef int LENGTH;
LENGTH length, width, height;
int length, width, height;
typedef struct {
int scruples;
int drams;
int grains;
} WEIGHT;
WEIGHT chicken, cow, horse, whale;
typedef int SCROLL(void);
extern SCROLL *yds;
typedef struct a { char x; } ex1, *ptr1;
typedef struct b { char x; } ex2, *ptr2;
Type ex1 is
compatible with the type struct a and the type of
the object pointed to by ptr1. Type ex1 is
not compatible with char, ex2, or struct
b.typedef class {
~Trees();
} Trees;
In this example,
an unnamed class is defined in a typedef definition. Trees is
an alias for the unnamed class, but not the class type name. So you
cannot define a destructor ~Trees() for this unnamed
class; otherwise, the compiler issues an error. In the C++0x standard, the extended friend declarations feature is introduced, with which you can declare typedef names as friends. For more information, see Extended friend declarations.