我想创建一个传递矢量作为参数的线程 . 但我得到以下错误:
error: invalid conversion from ‘int’ to ‘void* (*)(void*)’ [-fpermissive]
error: initializing argument 3 of ‘int pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*)’ [-fpermissive]
我有以下代码:
#include
#include
#include
using namespace std;
void* func(void* args)
{
vector* v = static_cast*>(args);
cout << "Vector size: " << v->size();
}
int main ( int argc, char* argv[] )
{
vector integers;
pthread_t thread;
for ( int i = 0; i < 10; i++)
integers.push_back(i+1);
// overheat call
//pthread_create( &thread, NULL, func, static_cast(&integers));
pthread_create( &thread, NULL,func,&integers);
cout << "Main thread finalized" << endl;
return 0;
}
我怎么能做得好呢?谢谢
编辑:忘了包含在这里发布的内容;修订 .
我遇到了新的错误:
error: stray ‘\305’ in program
error: stray ‘\231’ in program
我想知道它 .
提前致谢 .
FINAL EDIT : Thanks to all. Sorry, I had another int var called func in other location.
Thanks for your help.