Re: what is an enum?

Tech-Archive recommends: Speed Up your PC by fixing your registry



Hi Tom,

Thanks for the workaround! : )

[==P==]

"Tamas Demjen" <tdemjen@xxxxxxxxx> wrote in message
news:%23VfEuMcAGHA.2356@xxxxxxxxxxxxxxxxxxxxxxx
> Peteroid wrote:
>> int value ;
>> input >> value ; // ok
>> enum_var = value ; // error, can't convert?!
>
> int doesn't convert to an enum. You have to cast it:
>
> int value;
> input >> value;
> enum_var = static_cast<My_Enum>(value);
>
> Tom


.



Relevant Pages

  • Re: Why do enum values req explicit conversions
    ... that an enum is definitely an instance of System.Enum - proven by the fact ... I suppose the most important issue is that the syntax of the cast operator ... is actually an unbox operation is incorrect. ... If it were already an int, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Nullable Enum
    ... value - i.e. you cannot unbox float to int, or uint to int, or int to ... int, and are trying to unbox it to a different type, enum. ... Is there a way to achieve the type cast with a single statement? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: enum as index for DataRow
    ... public constant int Table1.Field1 = 0; ... > from myfields to int. ... > I REALLY do not want to have to cast every use of this enum. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: enum is int
    ... if (te is int) ... conversions, boxing conversions, and unboxing ... I don't have Visual Studio handy at the moment, but I'm suspicious of the idea that a boxed enum would successfully be cast to an int. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Casting in a generic function
    ... I want to avoid having to write custom convert functions for my enums so ... I want to convert to an int and cast to the enum, ... The cast fails inside the generic function even though its valid. ...
    (microsoft.public.dotnet.languages.csharp)