How to simplify multiple if-else-if statements in c++
问题 Suppose I have four functions for four cases: void ac() { //do something } void ad() { //do something } void bc() { //do something } void bd() { //do something } void f(bool a, bool b, bool c, bool d) { if(a and c) { ac(); } else if(a and d) { ad(); } else if(b and c) { bc(); } else if(b and d){ bd(); } else { throw 1; } } For the 2 by 2 situation it's quite simple, but in more complex situations, this can get very tedious. Is there a way to simplify this? 回答1: #define A 0x1 #define B 0x2