Простые имена типов
Имя простого типа — это имя, тип которого не является указателем, ссылкой, массивом или указателем функции.
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 )
Заметки
Имя простого типа может определяться спецификатором nested-name-specifier, указывающим пространство имен или содержащим класс.
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 и битовых полей целочисленных типов без знака не считается знаковым битом. |