小编Zee*_*Zon的帖子

无法从lambda构造

我遇到了编译问题.我不明白为什么下面的代码不能编译:

#include <functional>

namespace async {

template<class ...T>
using Callback = std::function<void(const std::string& result, T ...args)>;

template<class Signature>
class Function;

template<class Res, class ...Args>
class Function<Res(Args...)>
{
    std::function<void(Args ...args, const Callback<Res>&)> m_function;
public:
    Function(std::function<void(Args ...args, const Callback<Res>&)>&& function) : m_function(std::move(function)) {}
    Function& operator=(std::function<void(Args ...args, const Callback<Res>&)>&& function) {m_function = std::move(function); return *this;}
    void operator()(Args... args, const Callback<Res>& callback) const {m_function(args..., callback);}
};

}

async::Function<int(int)> getF()
{
    return [](int i, const async::Callback<int> callback)
    {
        callback("", i);
    };
}

int main(int argc, …
Run Code Online (Sandbox Code Playgroud)

c++ lambda templates c++11

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

标签 统计

c++ ×1

c++11 ×1

lambda ×1

templates ×1