If I remember right a C-Style conversion is nothing more than an ordered set of conversions static_cast, dynamic_cast, reinterpret_cast, static_cast...,
consider:
enum NUMBERS
{
NUMBER_ONE,
NUMBER_TWO
};
void Do( NUMBERS a )
{
}
int _tmain(int argc, _TCHAR* argv[])
{
unsigned int a = 1;
Do( a ); //C2664
return 0;
}
a C-Style conversion would do
Do( (NUMBERS)a );
What I would like to know is, what is the correct non C-Style conversion to be made, why?
The correct way would be:
Because:
Source: http://en.cppreference.com/w/cpp/language/static_cast
dynamic_castdoes runtime checks using RTTI, so it only applies to classes with at least one virtual method.reinterprest_castis designed to tell the compiler to treat a specific piece of memory as some different type, without any actual runtime conversions.