我只是試圖爲給定的std::bind
創建std::packaged_task
。C++創建std :: packaged_task的通用std :: bind
#include <functional>
#include <future>
class A
{
public:
template<class T>
void execute(T func)
{
std::packaged_task<T> task(func);
}
};
int main()
{
auto func = std::bind([](int x) { return x*x; }, 5);
A name;
name.execute(func);
}
main.cpp: In instantiation of 'void A::execute(T) [with T = std::_Bind(int)>]': main.cpp:20:20: required from here main.cpp:10:36: error: 'std::packaged_task(int)> > task' has incomplete type std::packaged_task task(func);
我使用G ++ 5.2.0,和C++ 14。
有人有想法嗎?
謝謝
'func'應該如何調用?如果有的話,它應該返回什麼? –
'auto'在參數聲明中是不允許的。 – 0x499602D2
問題是,它不能編譯 –