Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <future>
- using namespace std;
- int func(int m, int n) {
- return n*m;
- }
- int main() {
- std::packaged_task<int(int,int)> task(&func);
- auto f=task.get_future();
- std::thread t(std::move(task),3,11);
- t.join();
- std::cout<<f.get()<<std::endl;
- }
- /*
- 1>------ Build started: Project: ConsoleApplication7, Configuration: Debug Win32 ------
- 1>Build started 4/15/2012 11:14:47 PM.
- 1>InitializeBuildStatus:
- 1> Touching "Debug\ConsoleApplication7.unsuccessfulbuild".
- 1>ClCompile:
- 1> Source.cpp
- 1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(1140): error C2248: 'std::packaged_task<<unnamed-symbol>>::packaged_task' : cannot access private member declared in class 'std::packaged_task<<unnamed-symbol>>'
- 1> with
- 1> [
- 1> <unnamed-symbol>=int (int,int)
- 1> ]
- 1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\future(1839) : see declaration of 'std::packaged_task<<unnamed-symbol>>::packaged_task'
- 1> with
- 1> [
- 1> <unnamed-symbol>=int (int,int)
- 1> ]
- 1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\functional(1140) : while compiling class template member function 'std::_Bind<_Forced,_Ret,_Fun,_V0_t,_V1_t,_V2_t,_V3_t,_V4_t,_V5_t,<unnamed-symbol>>::_Bind(const std::_Bind<_Forced,_Ret,_Fun,_V0_t,_V1_t,_V2_t,_V3_t,_V4_t,_V5_t,<unnamed-symbol>> &)'
- 1> with
- 1> [
- 1> _Forced=false,
- 1> _Ret=void,
- 1> _Fun=std::packaged_task<int (int,int)>,
- 1> _V0_t=int,
- 1> _V1_t=int,
- 1> _V2_t=std::_Nil,
- 1> _V3_t=std::_Nil,
- 1> _V4_t=std::_Nil,
- 1> _V5_t=std::_Nil,
- 1> <unnamed-symbol>=std::_Nil
- 1> ]
- 1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\thread(50) : see reference to class template instantiation 'std::_Bind<_Forced,_Ret,_Fun,_V0_t,_V1_t,_V2_t,_V3_t,_V4_t,_V5_t,<unnamed-symbol>>' being compiled
- 1> with
- 1> [
- 1> _Forced=false,
- 1> _Ret=void,
- 1> _Fun=std::packaged_task<int (int,int)>,
- 1> _V0_t=int,
- 1> _V1_t=int,
- 1> _V2_t=std::_Nil,
- 1> _V3_t=std::_Nil,
- 1> _V4_t=std::_Nil,
- 1> _V5_t=std::_Nil,
- 1> <unnamed-symbol>=std::_Nil
- 1> ]
- 1> c:\users\petke\documents\visual studio 11\projects\consoleapplication7\consoleapplication7\source.cpp(12) : see reference to function template instantiation 'std::thread::thread<std::packaged_task<<unnamed-symbol>>,int,int>(_Fn,_V0_t &&,_V1_t &&)' being compiled
- 1> with
- 1> [
- 1> <unnamed-symbol>=int (int,int),
- 1> _Fn=std::packaged_task<int (int,int)>,
- 1> _V0_t=int,
- 1> _V1_t=int
- 1> ]
- 1>
- 1>Build FAILED.
- 1>
- 1>Time Elapsed 00:00:01.64
- ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement