···
Threadpool(size_t threadNum = 4,size_t queSize = 10);
···
如果构造类的时候价括号,会报错
···
int main()
Threadpool threadpool();//这个构造有问题
threadpool.start();
···
error: request for member ‘start’ in ‘threadpool’, which is of non-class type ‘wd::Threadpool()’
threadpool.start();
using std::vector;
using std::unique_ptr;
namespace wd
{
class Task;
class Thread;
class Threadpool
{
friend class WorkerThread;
public:
Threadpool(size_t threadNum = 4,size_t queSize = 10)
:_threadNum(threadNum)
,_queSize(queSize)
,_taskque(queSize)
,_isExit(false)
{
_threads.reserve(_threadNum);
}
~Threadpool();
void start();
void stop();
void addTask(Task *task);
private:
Task * getTask();
void threadfunc();
private:
size_t _threadNum;
size_t _queSize;
vector<unique_ptr<Thread> > _threads;
TaskQueue _taskque;
bool _isExit;
};
}
原文:https://www.cnblogs.com/prome6/p/11318731.html