Я хотел бы создать поток, передающий вектор в качестве параметра.
но я получил следующие ошибки:
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 <iostream>
#include <vector>
#include <pthread.h>
using namespace std;
void* func(void* args)
{
vector<int>* v = static_cast<vector<int>*>(args);
cout << "Vector size: " << v->size();
}
int main ( int argc, char* argv[] )
{
vector<int> 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<void*>(&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.