I am trying to make a function receive an enum as one of its parameters. I had the enum as a global but for some reason my other files couldn't change the enum. so I was wondering how do you set an enum as an argument for a function like,
function(enum AnEnum eee);
or is there a better way to solve the above problem?
Okay a quick rephrasing of my question: I basically have numerous files and I want all of them to have access to my enum and be able to change the state of that enum also the majority of files that should be able to access it are in a class. The way I was attempting to fix this was by passing the enum into the function that needed to access it, I couldn't work out how to go about making a function receive an enum as one of its arguments.
If you want to pass a variable that has a value of one of the enums 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 that's not what you mean, please clarify.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With