Question

If I use /clr:oldSyntax 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 an IceCreamFlavor to a function with the signature:

OrderFlavor(IceCreamFlavors flav)

by running

OrderFlavor(IceCreamFlavors::Sardine)

I get the error:

'IceCreamFlavors Sardine' : member function redeclaration not allowed
Was it helpful?

Solution

Try

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

OTHER TIPS

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

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

If you are, I would guess that you need to move it out so that it is its own class instead of a nested one. (Does managed c++ allow nested classes?) My impression is that you used to be able to do it unmanaged style inside another class, but since its its own class now, you probably shouldn't be nesting them. I might be wrong. My knowledge of managed c++ and c# is kind of weak.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top