C ++ function receiving an enumeration as one of its parameters

I am trying to make a function by getting an enumeration as one of its parameters. I had an enumeration as global, but for some reason my other files could not change the enumeration. so I was wondering how you set enum as an argument to a function like

function(enum AnEnum eee);

Or is there a better way to solve the above problem?

I paraphrase my question well: I basically have numerous files, and I want all of them to have access to my enumeration and to be able to change the state of this enumeration, as well as most of the files that should have access to it. are in the classroom. The way I tried to fix this was to pass enum to a function that was supposed to access it, I could not figure out how to make the function of getting an enumeration as one of my arguments.

+5
source share
2 answers

If you want to pass a variable that has the value of one of the enumeration values, this will do:

enum Ex{
  VAL_1 = 0,
  VAL_2,
  VAL_3
};

void foo(Ex e){
  switch(e){
  case VAL_1: ... break;
  case VAL_2: ... break;
  case VAL_3: ... break;
  }
}

int main(){
  foo(VAL_2);
}

If this is not what you mean, please clarify.

+9
source
(1) my other files couldn't change the enum

enum, constants. , enum.

(2) how do you set an enum as an argument for a function ?

enum,

void function (AnEnum &eee)
{
   eee = NEW_VALUE;
}
0

All Articles