When i try to compile my thread pool with one task i got following error :
error: 'void ThreadPool::enqueue(F) [with F = CConnection::handle()::]', declared using local type 'CConnection::handle()::', is used but never defined [-fpermissive]
Here is thread pool declaration :
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;
};
Here is function, what want to use thread pool to test :
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);
}
And here is enqueue definition :
template<class F>
void ThreadPool::enqueue(F f)
{
service.post(f);
}
Can some one found what I doing wrong ?
Is the definition of enqueue in the ThreadPool.h header? This is required for template methods
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.