8.1 类型名
8.1 类型名
1、进行显式类型转换,或作为sizeof,,new和typeid的参量时,需要指定类型的名字。类型名字可通过type-id给出,type-id在句法上等同于省略了名字的对象或函数声明。
type-id:
type-specifier-seq abstract-declaratoropt
type-specifier-seq:
type-specifier type-specifier-seqopt
abstract-declarator:
ptr-operator abstract-declaratoropt
direct-abstract-declarator
direct-abstract-declarator:
direct-abstract-declaratoropt
( parameter-declaration-clause ) cv-qualifier-seqopt exception-specificationopt
direct-abstract-declaratoropt [ constant-expressionopt ]
( abstract-declarator )
当构造为声明中的声明符时,能够唯一地确定标识符在abstract-declarator中的位置,进一步,type-id所命名的类型同这个假想的标识符具有相同的类型。例如:
int // int i
int * // int *pi
int *[3] // int *p[3]
int (*)[3] // int (*p3i)[3]
int *() // int *f()
int (*)(double) // int (*pf)(double)
分别命名了类型“int”,“pointer to int”,“array of 3 pointers to int”,“pointer to array of 3 int”,“返回int指针的无参函数”和“指向返回类型为int,参数类型为double的函数的指针”。
2、类型也能通过typedef(