Advertisement
Guest User

packaged_task and thread

a guest
Apr 15th, 2012
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <future>
  3. using namespace std;
  4.  
  5. int func(int m, int n) {
  6.     return n*m;
  7. }
  8.  
  9. int main() {
  10.     std::packaged_task<int(int,int)> task(&func);
  11.     auto f=task.get_future();
  12.     std::thread t(std::move(task),3,11);
  13.     t.join();
  14.     std::cout<<f.get()<<std::endl;
  15. }
  16.  
  17. /*
  18. 1>------ Build started: Project: ConsoleApplication7, Configuration: Debug Win32 ------
  19. 1>Build started 4/15/2012 11:14:47 PM.
  20. 1>InitializeBuildStatus:
  21. 1>  Touching "Debug\ConsoleApplication7.unsuccessfulbuild".
  22. 1>ClCompile:
  23. 1>  Source.cpp
  24. 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>>'
  25. 1>          with
  26. 1>          [
  27. 1>              <unnamed-symbol>=int (int,int)
  28. 1>          ]
  29. 1>          c:\program files (x86)\microsoft visual studio 11.0\vc\include\future(1839) : see declaration of 'std::packaged_task<<unnamed-symbol>>::packaged_task'
  30. 1>          with
  31. 1>          [
  32. 1>              <unnamed-symbol>=int (int,int)
  33. 1>          ]
  34. 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>> &)'
  35. 1>          with
  36. 1>          [
  37. 1>              _Forced=false,
  38. 1>              _Ret=void,
  39. 1>              _Fun=std::packaged_task<int (int,int)>,
  40. 1>              _V0_t=int,
  41. 1>              _V1_t=int,
  42. 1>              _V2_t=std::_Nil,
  43. 1>              _V3_t=std::_Nil,
  44. 1>              _V4_t=std::_Nil,
  45. 1>              _V5_t=std::_Nil,
  46. 1>              <unnamed-symbol>=std::_Nil
  47. 1>          ]
  48. 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
  49. 1>          with
  50. 1>          [
  51. 1>              _Forced=false,
  52. 1>              _Ret=void,
  53. 1>              _Fun=std::packaged_task<int (int,int)>,
  54. 1>              _V0_t=int,
  55. 1>              _V1_t=int,
  56. 1>              _V2_t=std::_Nil,
  57. 1>              _V3_t=std::_Nil,
  58. 1>              _V4_t=std::_Nil,
  59. 1>              _V5_t=std::_Nil,
  60. 1>              <unnamed-symbol>=std::_Nil
  61. 1>          ]
  62. 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
  63. 1>          with
  64. 1>          [
  65. 1>              <unnamed-symbol>=int (int,int),
  66. 1>              _Fn=std::packaged_task<int (int,int)>,
  67. 1>              _V0_t=int,
  68. 1>              _V1_t=int
  69. 1>          ]
  70. 1>
  71. 1>Build FAILED.
  72. 1>
  73. 1>Time Elapsed 00:00:01.64
  74. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
  75. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement