Casting of a Object* to an Enum value??

G

Guest

Hi everybody!

I have a problem with letting the compiler accept the following code in Managed C++, see example below.

I have a logfile that contains statements about variuos actions taken during an installation.
The actions has a value of a enum type itemOper = {FileCopy, FileMerge, FolderOk, ...} that is written to the logfile
by Enum::GetName(__typeof(itemOper), oper). No FlagAttribute is used on this enum type.
When i later read the logfile I want to translate the text "FileCopy" back into a value of type itemOper.
It works fine in runtime with the debugger and the following code:

Object * item = Enum::parse(__typeof(itemOper), S"FileCopy");

If I set a breakpoint at a line after this statement the debugger show that the variable item has the value "FileCopy", thats fine!!
Now to the problem. The compiler does not allow any cast's or a switch(oper) statement!!!.
It does not accept a "if (oper == itemOper::FileCopy)" and so on.

What to do, the base class Enum is usable at variuos points, but I'm stuck here.
Does anybody know how to "fool" the compiler or have the right solution??

/Thanks
 
M

Mattias Sjögren

Anders,

You have to unbox the value from the returned Object

itemOper oper = *dynamic_cast<__box itemOper*>(item);



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top