今天在改代码时发现了这两个warning,C4305 - 'identifier' : truncation from 'type1' to 'type2' 和C4800 - 'type' : forcing value to bool 'true' or 'false' (performance warning)。
大家看看下面的代码吧,一目了然。:)
int a1 = 1; int a2 = 2; MyEnum m = MyEnum::a; bool b = 1; // no warning b = 2; // warning C4305: '=' : truncation from 'int' to 'bool' b = a1; // warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning) b = a2; // warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning) b = MyEnum::a; // no warning b = m; // warning C4800: 'MyEnum' : forcing value to bool 'true' or 'false' (performance warning) b = !!a2; // no warning b = a2!=0; // no warning