简体   繁体   中英

Compiler errors when using a Boost::Thread with parameters

I would greatly appreciate any help here. I am trying to call a function asynchronously with Boost::Thread, but I am getting some errors. This is my real code.

In main:

vector<std::string> a = ...;
vector<std::string> b = ...;
vector<boost::thread> threads;

threads.push_back(boost::thread(do_work, an_integer, a[i], b.begin(), b.end()));

// Later I will join()...

Elsewhere:

void do_work(int i, std::string a_string, vector<string>::iterator begin, vector<string>::iterator end)
{
    // Some stuff
}

I am quite new to this stuff, being much more used to C#. Anyway, these are the errors I am getting:

error C2664: 'void (int,std::string,std::_Vector_iterator<_Myvec>,std::_Vector_iterator<_Myvec>)' : cannot convert parameter 1 from 'std::_Vector_iterator<_Myvec>' to 'int'

error C2664: 'void (int,std::string,std::_Vector_iterator<_Myvec>,std::_Vector_iterator<_Myvec>)' : cannot convert parameter 3 from 'std::basic_string<_Elem,_Traits,_Ax>' to 'std::_Vector_iterator<_Myvec>'

error C2664: 'void (int,std::string,std::_Vector_iterator<_Myvec>,std::_Vector_iterator<_Myvec>)' : cannot convert parameter 4 from 'std::_Vector_iterator<_Myvec>' to 'std::_Vector_iterator<_Myvec>'

I would greatly appreciate any help you could offer. I am almost certainly doing something extremely inane! Thanks a lot.

That compiler error says that b.begin() and b.end() are different types, which clearly can't be in the code you've listed. Recheck your code to make sure you haven't defined b to be something else. (Also check an_integer since the compiler believes it's an iterator.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM