Thanks for the response Vladimir, but that doesn't seem to work either.
That throws the compiler error C2440, cannot convert from
'System::Enum' to 'EnumType', which doesn't make any sense to me
because I thought that was the point of *dynamic_cast.
> That throws the compiler error C2440, cannot convert from
> 'System::Enum' to 'EnumType', which doesn't make any sense to me
> because I thought that was the point of *dynamic_cast.
In fact I succeed in such a conversion:
__value enum Color
{
Red,
Green,
Blue
};
int main(int argc, char* argv[])
{
Color color = *dynamic_cast<Color
*>(System::Enum::Parse(__typeof(Color), S"Green"));
System::Console::WriteLine(color);
}

Signature
Vladimir Nesterovsky
e-mail: vladimir@nesterovsky-bros.com
home: http://www.nesterovsky-bros.com
Jeremy - 15 Jul 2005 00:13 GMT
Okay, now I'm really confused. I've copied and pasted into a new
project, EXACTLY, and I get the compile error:
c:\Documents and Settings\jlueck\Desktop\C++.NET Projects\Enum
Test\Enum Test.cpp(23): error C2440: 'initializing' : cannot convert
from 'System::Enum' to 'Color'
*shrug* Is there an include or using namespace that I should be
worring about? I'm running VS .NET 2003 on an XP box...
Tomas Restrepo (MVP) - 15 Jul 2005 01:08 GMT
Jeremy,
> Okay, now I'm really confused. I've copied and pasted into a new
> project, EXACTLY, and I get the compile error:
[quoted text clipped - 5 lines]
> *shrug* Is there an include or using namespace that I should be
> worring about? I'm running VS .NET 2003 on an XP box...
Nope. It's just a long standing compiler problem. The solution is to use
static_cast<> instead with a bit of trickery. Try this:
Color color = *(static_cast<Color
__box*>(System::Enum::Parse(__typeof(Color), S"Green")));
FWIW, I talked about this in more detail in an article I wrote a while back
on MSDN magazine (see the unboxing section):
http://msdn.microsoft.com/msdnmag/issues/02/02/ManagedC/default.aspx

Signature
Tomas Restrepo
tomasr@mvps.org
http://www.winterdom.com/
Jeremy - 15 Jul 2005 18:17 GMT
Thanks Vladimir and Tomas for your help and that's an excellent article
Tomas.
Jeremy Lueck