【发布时间】:2013-03-01 10:37:59
【问题描述】:
我正在编写一个包含 pthread 的类,它的头文件和 .cpp 定义文件。
在 .h 中我有:
class test
{
public:
int a;
...
private:
typedef void (*myfunc)(void *p);
static myfunc pthreadRun;
}
在 .cpp 我有:
...
typedef void (*myfunc)(void *p);
myfunc test::pthreadRun
{
this->a = 10;
pthread_exit(NULL);
}
...
我收到一个错误:void (* test::pthreadRun)(void*) 不是class test 的静态成员,还有一堆其他错误,但这是第一个。
我很困惑,因为它被声明为静态:/
pthreadRun是pthread_create()的线程运行函数
我错过了什么?
【问题讨论】:
-
看here。您不能为此使用私有方法。至少不是这样……
-
你不能用 typedef 声明一个函数。
标签: c++ class pthreads header-files static-members