enum classes in c++.net

Hello,
I am trying to define and work with an “enum” class as I used to do in c++ but there is a problem when I use it in a CLR console application. My code is:
________________________________________________________________________
enum colors_t {black, blue, green, cyan, red, purple, yellow, white};

colors_t mycolor;

mycolor = black;
________________________________________________________________________
and I've got the next errors:

1>f:\c++projects\wholedemocontrol\newClasses.h(91) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>f:\c++projects\wholedemocontrol\newClasses.h(91) : error C2371: 'mycolor' : redefinition; different basic types

What am I doing wrong?
Thank you
closed account (z05DSL3A)
You need to do somthing along the lines of:
1
2
3
4
5
6
7
8
9
10
11
12
using namespace System;

enum class colors_t {black, blue, green, cyan, red, purple, yellow, white}; 

int main(array<System::String ^> ^args)
{
    colors_t mycolor;

    mycolor = colors_t::black;

    return 0;
}


If you want to mix managed and unmanaged try:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// compile with: /clr
enum class day {sun, mon, tue, wed, thu, fri, sat};
enum {sun, mon, tue, wed, thu, fri, sat} day2; // unnamed std enum

int main() {
   day a = day::sun;
   day2 = sun;
   if ((int)a == day2)
   // or...
   // if (a == (day)day2)
      System::Console::WriteLine("a and day2 are the same");
   else
      System::Console::WriteLine("a and day2 are not the same");
}
Last edited on
Topic archived. No new replies allowed.