I have a function as follows
void test(const int * x, int d){
for(int i=0; i<d ; i++)
cout<< x[i] << endl;
}
When I try to run it with a boost::thread
int n=10;
int * x1=new int[n];
boost::thread *new_thread = new boost::thread(& test,x1,n);
I get the following compilation error
error: no matching function for call to ‘boost::thread::thread(<unresolved overloaded function type>, int*&, uint16_t&)’
/usr/include/boost/thread/detail/thread.hpp:216: note: candidates are: boost::thread::thread(boost::detail::thread_move_t<boost::thread>)
/usr/include/boost/thread/detail/thread.hpp:155: note: boost::thread::thread()
/usr/include/boost/thread/detail/thread.hpp:123: note: boost::thread::thread(boost::detail::thread_data_ptr)
/usr/include/boost/thread/detail/thread.hpp:114: note: boost::thread::thread(boost::thread&)
main.cpp:397: warning: unused variable ‘new_thread’
Indeed, I'm newbie to boost. Thank you.
Looks like your test
function overloaded:
//here
void test(const int * x, int d){
for(int i=0; i<d ; i++)
cout<< x[i] << endl;
}
//somewhere
void test()
{
std::cout <<"hahahahaha\n";
}
Now, when you specify test
name
boost::thread *new_thread = new boost::thread(& test,x1,n);
Compiler cannot know, if you want to use one test
function, or another.
you should specify what overload you want to use:
boost::thread *new_thread = new boost::thread((void(*)(const int*, int)) test,x1,n);
or rename your test
function
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.