我从一个简单的例子开始 http://www.tutorialspoint.com/cplusplus/cpp_multithreading.htm 我需要划分不同的cpps和标题,如下所示
Process_Images.h中的类定义
void PrintHello(void* threadid);
在Process_Images.cpp
中void ProcessImages::PrintHello(void* threadid)
{
long tid;
tid = (long)threadid;
std::cout << "Hello World! Thread ID, " << tid << std::endl;
pthread_exit(NULL);
}
在主要功能
中ProcessImages PI;
pthread_t threads[2];
pthread_create(&threads[0],NULL,PI.PrintHello,(void *)i);
错误是 - &gt;
/home/nvidia/Desktop/cms/tools/vibrante-vcm30t124-linux/cmsapplication_export/cmsapplication/sampleThread.cpp:333:69: error: cannot convert ���ProcessImages::PrintHello��� from type ���void (ProcessImages::)(void*)��� to type ���void* (*)(void*)���
pthread_create(&threads[0],NULL,CarDetLEFT.PrintHello,(void *)i);
^
有什么建议吗?
答案 0 :(得分:1)
因为我在问题中看到了C ++ 11标签,所以绝对不需要越过pthread路线!
std::thread thr(&ProcessImages::PrinteHello, &PI, &i);
对你有好处!
答案 1 :(得分:0)
两个问题:
"Microsoft.AspNet.Hosting": "1.0.0-rc1-final"
,而不是void*
有关详细信息,请参阅pthread_create
的参考页。
因此,将void
的返回类型更改为ProcessImages::PrintHello
并将其设为void*
:
static
然后这应该更好:
class ProcessImages {
//<SNIP>
public :
static void* PrintHello(void* threadid);
//<SNIP>
};