简单类型名称

简单类型名称是简单类型(即不是指针、引用、数组或函数指针的类型)的名称。

class-name
[ :: ] nested-name-specifier type-name
[ :: ] nested-name-specifier template template-id 
char 
wchar_t 
bool 
short 
int 
long 
signed 
unsigned 
float 
double 
void 
auto 
decltype ( expression )

备注

简单类型名称可由嵌套名称说明符限定,指示命名空间或包含类。

int  // simple type name
unsigned int  // combination of simple type names 
MyClass  // a class type
class MyClass  // class is optional when using the type name
struct MyStruct  // the keyword struct is optional in C++
enum MyEnum  // the keyword enum is optional in C++
::MyClass  // type name at global scope
Outer::Inner  // nested type name
::Outer::Inner  // nested type names with global scope operator
MyTemplate<int>  // a class template
Outer::Inner<int> // an inner class template
Outer<char>::Inner<int>  // an inner class template of a template class
::template MyTemplate<int>  // using the template keyword
typename MyClass  // the typename keyword (only in a template definition)

下表显示如何结合使用简单类型名称。

类型名称组合

类型

可一起显示的类型

注释

int

long 或 short,但不能与这二者同时显示

类型 int 暗指类型 long int。

long

int 或 double

类型 long 暗指类型 long int。

short

int

类型 short 暗指类型 short int。

signed

char、short、int 或 long

类型 signed 暗指 signed int。 signed char 类型的对象的最高有效位和带符号整数类型的位域将用作符号位。

unsigned

char、short、int 或 long

类型 unsigned 暗指 unsigned int。 unsigned char 类型的对象的最高有效位和无符号整数类型的位域将不会视为符号位。

请参见

参考

C++ 类型说明符

auto 关键字(类型推导)

decltype 类型说明符