I have an enum with four keys I'm taking as input for an interface program and I'd like to pass the enum by value to the interface function, which has become quite long. The enum is like this:
enum MYKEYS {
W, S, O, L
};
There's also a boolean array that I have to pass by reference, which is also a little tricky.
bool key[4] = { false, false, false, false };
Does anyone know the proper syntax to pass both of these as reference in a function, similar to:
function(int & anintreference);
You can't pass the enum
itself as a parameter of your function! The enum
defines a new type, and you can create a variable of this type, that may take one of the value defined by the enum
:
MYKEYS k = W;
Only then you could pass k
by reference to some function:
function foo(MYKEYS& k_);
Regarding your second question, since you should think of the array as a pointer to a series of bool
:
function bar(bool* key, int length);
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