Type-casting enum to integer and vice versa

Viewed 44612

I have an enum

enum MYENUM
{
  VAL_1 = 0,
  VAL_2,
  VAL_3
};

and two functions that have integer and enum as parameters respectively

void MyIntegerFunction(int integerValue)
{
...
}

void MyEnumFUnction(MYENUM enumValue)
{
...
}

I have two variables

int intVar = 10;
MYENUM enumVar = VAL_2;

In which of the two cases below is it correct to do a typecasting while calling these functions and why?

Case#1. MyEnumFUnction(static_cast<MYENUM>(intVar));
Case#2. MyIntegerFunction(static_cast<int>(enumVar));

PS: No C++11

1 Answers
Related