The correct way to declare an enum in Managed C ++ 2005?

If I use / clr: oldSyntax then the following should work:

public __value enum IceCreamFlavors
{
   Vanilla,
   Chocolate,
   Sardine,
};

      

what is the equivalent in non-oldSyntax? How do I declare a "managed" enum in Managed C ++ for .NET 2.0?

Edit: when I follow JaredPar's advice, then if I try to pass IceCreamFlavor to a function with a signature:

OrderFlavor(IceCreamFlavors flav)

      

running

OrderFlavor(IceCreamFlavors::Sardine)

      

I am getting the error:

'IceCreamFlavors Sardine' : member function redeclaration not allowed

      

+1


source to share


2 answers


Try



enum class IceCreamFlavors {
  Vanilla,
  Chocolate,
  Sardine,
};

      

+2


source


Are you, by any chance, trying to declare your enum inside another class? i.e:

public ref class Icecream
{
     public enum class flavours
     {
          Mint,
          Vanilla,
          Guac
     };
};

      



If you are, I would suggest that you need to move it so that it is its own class and not nested. (Is Managed C ++ Allowing Nested Classes?) I was under the impression that you were using this unmanaged style inside another class, but since it's now its own class, you probably shouldn't nest them. I might be wrong. My knowledge of managed C ++ and C # is weak.

0


source







All Articles