Use a lambda as a parameter for a C++ function

后端 未结 3 1314
南笙
南笙 2020-12-09 16:04

I would like to use a lambda as a parameter for a C++ function, but I don\'t know which type to specify in the function declaration. What I would like to do is this:

3条回答
  •  温柔的废话
    2020-12-09 16:21

    You have 2 ways: make your function template:

    template 
    void myFunction(F&& lambda){
        //some things
    }
    

    or erase type with std::function

    void myFunction(const std::function& f){
        //some things
    }
    

提交回复
热议问题