2013-06-01 89 views
0

當我嘗試編譯我的線程池一個任務,我得到了以下錯誤:線程池編譯錯誤

error: 'void ThreadPool::enqueue(F) [with F = CConnection::handle()::]', declared using local type 'CConnection::handle()::', is used but never defined [-fpermissive]

這裏是線程池的聲明:

class ThreadPool { 
public: 
    ThreadPool(size_t); 
    template<class F> 
    void enqueue(F f); 
    ~ThreadPool(); 
private: 
    // need to keep track of threads so we can join them 
    std::vector< std::unique_ptr<boost::thread> > workers; 

    // the io_service we are wrapping 
    boost::asio::io_service service; 
    boost::asio::io_service::work working; 
    friend class Worker; 
}; 

這裏是功能,什麼都想使用線程池來測試:

void CConnection::handle() 
{ 
    ThreadPool pool(4); 
    pool.enqueue([1] 
    { 
     std::cout << "hello " << 1 << std::endl; 
     boost::this_thread::sleep(
      boost::posix_time::milliseconds(1000) 
     ); 
     std::cout << "world " << 1 << std::endl; 
    }); 
    char * databuffer; 
    databuffer = new char[16]; 
    for(int i = 0;i<16;i++) 
    { 
     databuffer[i] = 0x00; 
    } 
    databuffer[0] = 16; 
    databuffer[4] = 1; 
    databuffer[8] = 1; 
    databuffer[12] = 1; 
    asynchronousSend(databuffer, 16); 

} 

這裏是排隊的定義:

template<class F> 
void ThreadPool::enqueue(F f) 
{ 
    service.post(f); 
} 

可有一個人找到了我做錯了嗎?

回答

2

是在ThreadPool.h頭入列的定義是什麼?這是必需的模板方法

+0

不,定義在ThreadPool.cpp –

+0

@Kacper好吧,這就是我的意思。它需要在標題 – Guillaume

+0

它的工作原理,謝謝:我會在7分鐘內接受答案。 –