C++ macro with lambda argument using 2+ captured elements generates error

后端 未结 2 708
长发绾君心
长发绾君心 2021-01-19 04:59
foo(const std::function& functor) {
    ....
}

#define MACRO_EXAMPLE(functor) foo(functor)

int main() {
    int i = 0, j = 0;
    MACRO_EXAMPLE([         


        
2条回答
  •  长发绾君心
    2021-01-19 05:36

    Add one more round of parenthesis:

    MACRO_EXAMPLE(([i, j](){}));
    //            ^          ^
    

    Otherwise the part before , is interpreted as macro's first parameter, and the part after , is interpreted as the macro's second parameter.

提交回复
热议问题