I cannot pass lambda as std::function

前端 未结 2 1409
遥遥无期
遥遥无期 2020-12-01 05:04

Let\'s focus on this example:

template
class C{
    public:
    void func(std::vector& vec, std::function

        
2条回答
  •  情话喂你
    2020-12-01 05:38

    It's because the argument (std::function) is a reference. It should be:

    void func(std::vector& vec, std::function f)
                                                                    ^  ^
                                                                       |
                                                                       f not a reference
    

    So that the argument can be converted to the parameter type.

    Also, the type of the function should match. I.e. it should accept a string reference.

提交回复
热议问题