You can use a map with function pointers.
int addition(int a, int b){ return a + b; } std::map<char, int(*)(int, int)> operators; operators.insert(make_pair('+', addition)); char c = getch(); int first_operand = 10; int second_operand = 20; int result = operators[c](first_operand, second_operand);
source share