Monday, October 31, 2011

The Keyword typedef

Some usages for the keyword typedef.

  1. Introduce a synonym for fundamental types.
    typedef int Integer;
  2. Introduce a synonym for pointer types.
    typedef char *pChar;
  3. Introduce a synonym for reference types.
    typedef double &refDouble;
  4. Introduce a synonym for struct, union, enum in C.
    typedef struct {int key; NODE *next;} NODE;
  5. Introduce a synonym for struct or class in C++.
    typedef class Old New;
    typedef Old New;
  6. Introduce a synonym for array types.
    typedef double dArray[10];
  7. Introduce a synonym for function types.
    typedef void Func(int, double);
  8. Introduce a synonym for function pointer types.
    typedef (void *)FuncPtr(int, double);

No comments:

Post a Comment