我在项目中声明了以下内容:

enum class OType : bool { Dynamic=true, Static=false };
OType getotype();


我正在使用以下功能:

double ComputeO(double K,bool type)


我这样称呼它:

ComputeO(some double, static_cast<bool>(getotype()))

对于此static_cast,我得到了一个不错的结果:

warning C4800: 'const dmodel::OType ' : forcing value to bool 'true' or 'false' (performance warning)


我不知道如何摆脱它,我明确指定了演员表是否足够?

注意:我正在使用VC11(Visual Studio 2012)

THKS。

最佳答案

请参阅https://msdn.microsoft.com/en-us/library/b6801kcy.aspx,其中描述了警告。特别是说:


  将表达式强制转换为bool不会禁用警告,
  这是设计使然。


像这样重写您的呼叫:

enum class OType : bool { Dynamic=true, Static=false };
OType getotype();
double ComputeO(double K,bool type);

int main()
{
    ComputeO(1.0, getotype() == OType::Dynamic);
}

08-04 04:17