相关疑难解决方法(0)

C++ 1y没有从std :: bind到std :: function的可行转换

我试图存储一个前向功能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 = …

c++ c++11 c++14

20
推荐指数
1
解决办法
4397
查看次数

标签 统计

c++ ×1

c++11 ×1

c++14 ×1