C++的C4305和C4800的编译警告

今天在改代码时发现了这两个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
 

posted on 2013-05-24 11:05  fresky  阅读(501)  评论(0编辑  收藏  举报

导航