I am trying to run the following program using boost::thread.
#include <boost/thread.hpp>
#include <iostream>
using namespace std;
class test{
public:
void hello(int i)
{
cout << i << " ";
};
};
int main(int argc, char* argv[])
{
class test t;
boost::thread thrd(t.hello, 10);
thrd.join();
return 0;
}
It is throwing an error while compiling as given below:
thread.c:17:33: error: no matching function for call to
‘boost::thread::thread(, int)’
/usr/include/boost/thread/detail/thread.hpp:236:9: note: candidates
are: boost::thread::thread(F, A1) [with F = void (test::*)(int), A1 =
int] /usr/include/boost/thread/detail/thread.hpp:202:9: note:
boost::thread::thread(boost::detail::thread_move_t)
I am using boost 1.42. I have also tried old style boost::thread creation.
When hello() is not a class function, everything goes fine. Please let me know how can I fix it?
The problem is you are try to bind to a member function try the following (i don’t have your boost version so have no idea if this works for sure)
Failing that you can use a binder
If your compiler is new enough you can use the standard library equivalents of all of those by changing the boost namespace for std:: (the placeholder are in std::placeholders not the global namespace).