Compiler Warning (level 1) C4305 'identifier' : truncation from 'type1' to 'type2'The specified identifier type was converted to a smaller type. Information was lost in the casting.
这个是基础,应该写成: float a = 4.1f; // 注意有字母f在C++里,默认的小数类型是double,出现const是因为4.1是一个常数。
这是由于编译器会将浮点常量默认地看作double,所以将会出现截断的警告。 为了避免警告,你可以将这个常量显式声明为float常量: float a = 4.1f;
'identifier' : truncation from 'type1' to 'type2'The specified identifier type was converted to a smaller type. Information was lost in the casting.
float a = 4.1f; // 注意有字母f在C++里,默认的小数类型是double,出现const是因为4.1是一个常数。
为了避免警告,你可以将这个常量显式声明为float常量:
float a = 4.1f;
应该是float a = 4.1f;