If I wanted to represent states or options or something similar using binary "flags" so that I could pass them and store them to an object like OPTION1 | OPTION2
where OPTION1
is 0001 and OPTION2
is 0010, so that what gets passed is 0011, representing a mix of the options.
How would I do this in C++? I was thinking something like
enum Option {
Option_1 = 0x01,
Option_2 = 0x02,
Option_3 = 0x04,
//...
}
void doSomething(Option options) {
//...
}
int main() {
doSomething(Option_1|Option_2);
}
But then ideally, doSomething
knows how to interpret the given Option.
Am I on the right track? Is there a better way?
Update
And wouldn't I have to define an Option
for every possible combination, also?