Type names are used in some declarators in the following ways:
In explicit conversions
As arguments to the sizeof operator
As arguments to the new operator
In function prototypes
In typedef statements
A type name consists of type specifiers, covered in Chapter 6, and abstract declarators, discussed in “Abstract Declarators”.
In the following example, the arguments to the function strcpy are supplied using their type names. In the case of the source argument, const is the specifier and char * is the abstract declarator:
static char __far *szBuf, *strcpy( char *dest, const char *source );
type-name:
type-specifier-list abstract-declaratoropt
type-specifier-list:
type-specifier type-specifier-listopt
abstract-declarator:
ptr-operator abstract-declaratoropt
abstract-declaratoropt(argument-declaration-list)cv-qualifier-listopt
abstract-declaratoropt[constant-expressionopt]
(abstract-declarator)
An abstract declarator is a declarator that does not declare a name—the identifier is left out. For example:
char *
declares the type “pointer to type char.” This abstract declarator can be used in a function prototype as follows:
char *strcmp( char *, char * );
In the above prototype (declaration), the function's arguments are specified as abstract declarators. The following is a more complicated abstract declarator that declares the type “pointer to a function that takes two arguments, both of type char *,” and returns type char *:
char * (*)( char *, char * )
Since abstract declarators completely declare a type, it is legal to form expressions of the form:
// Get the size of array of 10 pointers to type char.
size_t nSize = sizeof( char *[10] );
// Allocate a pointer to a function that has no
// return value and takes no arguments.
typedef void (PVFN *)();
PVFN *pvfn = new PVFN;
// Allocate an array of pointers to functions that
// return type WinStatus, and take one argument of
// type WinHandle.
typedef WinStatus (PWSWHFN *)( WinHandle );
PWSWHFN pwswhfnArray[] = new PWSWHFN[10];