C++ Linux C:必须调用对非静态成员函数的引用
我收到C++ Linux C:必须调用对非静态成员函数的引用,c++,linux,C++,Linux,我收到错误:必须调用对非静态成员函数的引用以尝试生成以下代码: HTTPClient::HTTPClient(int id,HttpListener& message) { pthread_t thId; pthread_create(&thId, NULL, processor, this); <--error is here } void* HTTPClient::processor(void* userData) { HTTPClient*
错误:必须调用对非静态成员函数的引用以尝试生成以下代码:
HTTPClient::HTTPClient(int id,HttpListener& message) {
pthread_t thId;
pthread_create(&thId, NULL, processor, this); <--error is here
}
void* HTTPClient::processor(void* userData) {
HTTPClient* client = static_cast<HTTPClient*>(userData);
client->run();
}
void HTTPClient::run() {
while(true) {
pthread_mutex_lock(&mMutex);
pthread_cond_wait(&mCond,&mMutex);
httpLoadFile(mUrl, mPath);
pthread_mutex_unlock(&mMutex);
}
}
HTTPClient::HTTPClient(int-id、HttpListener和message){
pthread_t thId;
pthread_create(&thId,NULL,processor,this);run();
}
void HTTPClient::run(){
while(true){
pthread_mutex_lock(&mMutex);
pthread_cond_wait(&mCond,&mMutex);
httpLoadFile(mUrl,mPath);
pthread_mutex_unlock(&mMutex);
}
}
我找到了一些解决错误的方法,但是失败了 它说您不能将指向方法的指针传递到pthread\u create
,您应该传递指向普通函数的指针。您忘记问问题了。你到底看到了什么问题?你看到的是什么错误?pTrac是C++库,所以它对C++成员函数处理得不太好,但是你可以用一个简单的lambda作为一个解决方案<代码> pthRead创建((th.th.d[/],null),[{ this ](空隙*ARG){返回->处理器(ARG);},这个);代码>虽然传递这个
看起来有点傻,如果它已经在lambda中被捕获了