开发者

C++0x error : variable 'std::packaged_task<int> pt1' has initializer but incomplete type

Below is a simple program in c++0x that makes use of packaged_task and futures. while compiling the program i get error : variable 'std::packaged_task pt1' has initializer but incomplete type

the program is below

#include <future>
#include <iostream>

using namespace std;


int printFn()
{

    for(int i = 0; i < 100; i++) 
    {

        cout << "thread " <<  i << endl;
    }
return 1;
}



int main()
{

   packaged_task<int> pt1(&printFn);

   future<int> fut =  pt1.get_future();

   t开发者_开发百科hread t(move(pt1));

   t.detach();

   int value  = fut.get();

   return 0;
}


The class template packaged_task is undefined for the general case. Only a partial specialization for function type parameters is defined. See the current draft:

template<class> class packaged_task; // undefined

template<class R, class... ArgsTypes>
class packaged_task<R(ArgTypes...)> {
   ...
   void operator()(ArgTypes...);
   ...
};

Since your printFn function doesn't take any parameters and returns an int you need to use the packaged_task<int()> type.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜