managed enumerated type and ++ operator

  • Thread starter Thread starter Daniel Wilson
  • Start date Start date
D

Daniel Wilson

I have an enumerated type like this:
public __value enum MyType{
ABC = 1,
DEF = 2,
GHI = 3,
JKL = 4
};

Later I have a for loop like this:
for (ft = MyType::ABC; ft <= MyType::JKL; ft++){

//Do stuff

}

I then get a compile error C2676: binary '++': 'MyType' does not define this
operator or a converstion to a type acceptable to the predefined operator.

So I tried to define the ++ operator.

MyType operator++(MyType &ft, int){

return ft = (MyType)(ft+1);

}

That gives me compile error C3281: 'operator` ++": global operator cannot
have managed type 'MyType __gc &' in signature.

So my question: How do I get a managed enumerated type to allow me to use
the ++ operator to iterate through its values?

dwilson
 
if you make that "ft" an "int" type, then it should work.

i guess you did

MyType ft;

you can do:

int ft;

// your for loop goes here
 
I have a solution, albeit a clunky one. I just change the for loop:

for (int i = MyType::ABC; i <= MyType::JKL; i++){
ft = (MyType) i;
//Do stuff
}

dwilson
 
Back
Top