2013-08-25 5 views
0

현재 C++을 배우려고하는데 이해가 안되는 컴파일러 오류가 하나 있습니다. 누군가 제발 컴파일러 오류가 무슨 뜻인지 설명해 주시겠습니까?C++ 컴파일러 오류 '함수 호출 호출 없음'

1 #include <thread> 
2 #include <vector> 
3 #include <iostream> 
4 
5 namespace thread_pool { 
6 
7 class worker { 
8  public: 
9  worker(); 
10  private: 
11 }; 
12 
13 worker::worker() { std::cout << "hello from worker\n"; } 
14 
15 class pool_keeper { 
16  public: 
17  pool_keeper(int); 
18  private: 
19  std::vector<std::thread> workers_; 
20  int pool_size_; 
21 }; 
22 
23 pool_keeper::pool_keeper(int pool_size) { 
24  int i; 
25  pool_size_ = pool_size; 
26  for (i=0; i<pool_size_; i++) 
27  workers_.push_back(std::thread(worker())); 
28 } 
29 } 

컴파일러는 나에게이 제공 :

In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/thread:39:0, 
      from 01.cpp:1: 
/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/functional: In member function ‘void std::_Bind_result<_Result, _Functor(_Bound_args ...)>::__call(std::tuple<_Args ...>&&, std::_Index_tuple<_Indexes ...>, typename std::_Bind_result<_Result, _Functor(_Bound_args ...)>::__enable_if_void<_Res>::type) [with _Res = void, _Args = {}, int ..._Indexes = {}, _Result = void, _Functor = thread_pool::worker, _Bound_args = {}, typename std::_Bind_result<_Result, _Functor(_Bound_args ...)>::__enable_if_void<_Res>::type = int]’: 
/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/functional:1378:24: instantiated from ‘std::_Bind_result<_Result, _Functor(_Bound_args ...)>::result_type std::_Bind_result<_Result, _Functor(_Bound_args ...)>::operator()(_Args&& ...) [with _Args = {}, _Result = void, _Functor = thread_pool::worker, _Bound_args = {}, std::_Bind_result<_Result, _Functor(_Bound_args ...)>::result_type = void]’ 
/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/thread:117:13: instantiated from ‘void std::thread::_Impl<_Callable>::_M_run() [with _Callable = std::_Bind_result<void, thread_pool::worker()>]’ 
      01.cpp:29:1: instantiated from here 
/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/functional:1287:4: error: no match for call to ‘(thread_pool::worker)()’ 

내가 컴파일러 오류가 표준 : : 스레드의 코드를 보면 무엇을 의미하는지 이해하려고 노력했지만, 내가 앞으로 더 좋은 방법이 생각 솔루션에.

답변

3

이 메시지는 컴파일러가 thread_pool::worker 유형의 개체를 호출하는 방법을 알지 못했음을 의미합니다. std::thread 생성자에는 호출 할 수있는 객체, 즉 operator()이 정의 된 함수 또는 객체가 필요합니다.

해결 방법은 thread_pool::worker의 생성자에서 operator()()으로 작업을 이동하는 것입니다.