【发布时间】:2016-08-14 21:38:36
【问题描述】:
我的pthread_t 线程有以下封装:
#include <pthread.h>
class Thread
{
public:
void run(const int);
static void *run_helper(void *);
bool startThread(int);
void joinThread();
pthread_t th;
};
run 是我的线程例程,run_helper 如下:
void *Thread::run_helper(int num)
{
return (Thread *)this->run(num);
}
我这样开始我的线程:
bool Thread::startThread(intptr_t arg)
{
return (pthread_create(&this->th, NULL, &run_helper(arg), (void *)(intptr_t)arg));
}
但是当我编译时,我得到以下错误:
错误:需要左值作为一元“&”操作数 return (pthread_create(&this->th, NULL, &run_helper(arg), (void *)(intptr_t)arg));
错误:“this”对于静态成员函数不可用 return (Thread *)this->run(num);
尽管尝试过,但我似乎无法使这种封装工作。
【问题讨论】:
标签: c++ multithreading pthreads