Tuesday, March 15, 2011

Proper way to declare an enum in Managed C++ 2005?

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
From stackoverflow
  • Try

    enum class IceCreamFlavors {
      Vanilla,
      Chocolate,
      Sardine,
    };
    
    brian : When I do that, if I try to pass an IceCreamFlavor to a function with the signature: "OrderFlavor(IceCreamFlavors flav)" by running "OrderFlavor(IceCreamFlavors::Sardine)" I get "'IceCreamFlavors Sardine' : member function redeclaration not allowed"

0 comments:

Post a Comment