【问题标题】:Thread Pool compile error线程池编译错误
【发布时间】:2013-05-28 10:34:41
【问题描述】:

当我尝试用一​​项任务编译我的线程池时,出现以下错误:

错误:'void ThreadPool::enqueue(F) [with F = CConnection::handle()::]',使用本地类型声明 'CConnection::handle()::',已使用但从未定义 [-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);
}

有人能发现我做错了吗?

【问题讨论】:

    标签: c++ boost-asio threadpool boost-thread


    【解决方案1】:

    ThreadPool.h 头文件中是否定义了 enqueue?这是模板方法所必需的

    【讨论】:

    • @Kacper 好的,这就是我的意思。它需要在标题中
    猜你喜欢
    • 1970-01-01
    • 2015-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-15
    • 2021-12-07
    相关资源
    最近更新 更多