Jim Langston Guest
|
Posted: Fri Aug 18, 2006 8:21 am Post subject: How defined is this? |
|
|
Problem: I want to pass an Enum as an integer reference.
Solution:
void MyFunc ( int& MyInt )
{
std::cout << "Value is:" << MyInt << std::endl;
}
enum Enumerator
{
ZERO = 0,
ONE,
TWO,
THREE
};
int main()
{
Enumerator MyEnum = ONE;
if ( sizeof( MyEnum ) == sizeof( int ) )
MyFunc( *reinterpret_cast<int*>( &MyEnum ) );
}
Is this guaranteed to work if sizeof( Enumerator ) == sizeof( int ) ?
By work I mean is this program guaranteed to output 1 in all cases? |
|