avatar.ds
July 16th, 2006, 10:16 AM
This seems very strange to me but I can't cast an integer to an integer-based enum in c++/cli.
Consider this:
enum Currency : int
{
Currency_USDollar = 0,
Currency_EUEuro = 1,
};
ref class Test
{
void CycleCurrencies()
{
for(int C = 1; C>0; C--)
{
DoSomethingWithCurrency(Currency(C));
DoSomethingWithCurrency(static_cast<Currency>(C));
DoSomethingWithCurrency(safe_cast<Currency>(C));
};
};
void DoSomethingWithCurrency(Currency _Currency) //
{ Currency C = _Currency; }; // "UNDEFINED VALUE?!?!?!?!?"
};
This code does not work no matter which casting I use! Also, when watched from the debugger, it shows "undefined value" for the cast enums.
What am I doing wrong here? It's such a basic stuff for c++, I'm amazed I ran into this curious problem.
Consider this:
enum Currency : int
{
Currency_USDollar = 0,
Currency_EUEuro = 1,
};
ref class Test
{
void CycleCurrencies()
{
for(int C = 1; C>0; C--)
{
DoSomethingWithCurrency(Currency(C));
DoSomethingWithCurrency(static_cast<Currency>(C));
DoSomethingWithCurrency(safe_cast<Currency>(C));
};
};
void DoSomethingWithCurrency(Currency _Currency) //
{ Currency C = _Currency; }; // "UNDEFINED VALUE?!?!?!?!?"
};
This code does not work no matter which casting I use! Also, when watched from the debugger, it shows "undefined value" for the cast enums.
What am I doing wrong here? It's such a basic stuff for c++, I'm amazed I ran into this curious problem.