0

I have the following declared in my project:

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

I'm using the following function:

double ComputeO(double K,bool type)

I'm calling it this way :

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

For this static_cast I'm getting a nice:

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

I don't know how to get rid of it,I specify the cast explicitly shouldnt it be enough ?

Note: I'm using VC11 ( Visual Studio 2012 )

Thks.

user2164703
  • 199
  • 1
  • 11

1 Answers1

2

See https://msdn.microsoft.com/en-us/library/b6801kcy.aspx, which describes the warning. In particular, it says:

Casting the expression to type bool will not disable the warning, which is by design.

Just rewrite your call like this:

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

int main()
{
    ComputeO(1.0, getotype() == OType::Dynamic);
}
Christian Hackl
  • 27,051
  • 3
  • 32
  • 62