C++11: “narrowing conversion inside { }” with modulus

后端 未结 4 1550
梦如初夏
梦如初夏 2020-12-04 02:32

I try to compile the following code with gcc and C++11 enabled:

unsigned int id = 100;
unsigned char array[] = { id % 3, id % 5 };
         


        
4条回答
  •  鱼传尺愫
    2020-12-04 02:55

    You may use:

    unsigned char array[] = {
        static_cast(id % 3),
        static_cast(id % 5)
    };
    

提交回复
热议问题