Explicit Type Conversion and Multiple Simple Type Specifiers

后端 未结 4 1395
执笔经年
执笔经年 2020-12-03 12:38

To value initialize an object of type T, one would do something along the lines of one of the following:

T x = T();
T x((T()));
<
4条回答
  •  难免孤独
    2020-12-03 13:13

    7.1.5.2:

    The simple-type-specifiers specify either a previously-declared user-defined type or one of the fundamental types`

    This implies that unsigned int i = unsigned int() is legal, since unsigned int is a fundamental type (and thus a simple-type-specifier, see 3.9.1).

    same applies for types like:

    long double
    long long
    long long int
    unsigned long
    unsigned long long int
    short int
    ...
    

提交回复
热议问题