Explicit Type Conversion and Multiple Simple Type Specifiers

后端 未结 4 1390
执笔经年
执笔经年 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条回答
  •  Happy的楠姐
    2020-12-03 12:58

    Hmm, sometimes you need a typedef. If it doesn't say a diagnostic is required, then it's not incorrect for them to support this. Nevertheless, for portability, you can use a typedef (uint16_t or uint64_t, although those might not be right), or quote the typename with a template:

    iterator::value_type( 5 )
    

    How's that for unreasonably verbose?

    Edit: Duh, or simply 5ul. That leaves unsigned short, unsigned char, and signed char as the only types you can't easily explicitly construct.

提交回复
热议问题