我的代码试图传递一个std :: map作为线程的引用,但似乎有些不好并导致
error: invalid conversion from ‘void* (*)(std::map<std::basic_string<char>,
std::vector<std::basic_string<char> > >)’ to ‘void* (*)(void*)’ [-fpermissive]
Run Code Online (Sandbox Code Playgroud)
我需要将map传递给线程并在该线程中插入map的键和值,并在成功之后.在主进程中,我需要更新或复制(线程映射)在同一映射的另一个对象,即myMapcache
int main()
{
std::map< std::pair<std::string , std::string> , std::vector<std::string> > myMap,myMapCache;
pthread_t threads;
//how to pass map object in thread as reference
int rc = pthread_create(&threads, NULL, myfunction, std::ref(myMap));
if (rc)
{
cout << "Error:unable to create thread," << rc << endl;
exit(-1);
}
// if true then update to local myMapCache
if(update)
{
std::copy(myMap.begin(), myMap.end(), std::inserter(MyMapCache, myMapCache.end()) );
}
}
void * …
Run Code Online (Sandbox Code Playgroud)