Passing operator as a parameter

后端 未结 4 1547
我在风中等你
我在风中等你 2021-02-05 03:25

I want to have a function that evaluates 2 bool vars (like a truth table)

for example:

since

T | F : T

then

myfunc(\'t\', \'f         


        
4条回答
  •  隐瞒了意图╮
    2021-02-05 03:33

    @ybungalobill posted a C++ correct answer and you should stick to it. If you want to pass the operators, functions will not work, but macros would do the work:

    #define MYFUNC(lv, rv, op) ....
    
    // Call it like this
    MYFUNC('t', 'f', ||);
    

    Be careful, macros are evil.

提交回复
热议问题