我试图存储一个前向功能std::function.如果我使用std::bind,我收到错误消息no viable conversion from ....如果我使用lambda,它编译好了.
这是示例代码
#include <functional>
template<typename Handler>void func1(int a, Handler&& handler) {}
template<typename Handler>void func2(Handler&& handler)
{
// this line compile fine
std::function<void ()> funcA = [handler = std::move(handler)]() { func1(1, std::move(handler)); };
// this line got compile error
std::function<void ()> funcB = std::bind(func1<Handler>, 1, std::move(handler));
}
int main()
{
func2(&main); // this just a sample, I am using functor as argument in real code
}
Run Code Online (Sandbox Code Playgroud)
尝试g ++ --std = …