
Monica Gretzer wrote:
Hi,
I want to pass data to a thread function. My question is- what is wrong with this code? The compiler error output is: "error: function returning a function". In the code below I am trying to pass an int to the thread function.
// ------------- code: how to pass data to the thread ? ---------------- #include
#include #include <iostream> using namespace std;
class TestThread { public: void thread(int a); void CreateThreads(void); };
void TestThread::thread(int a) { cout << "I am thread " << a << endl; }
void TestThread::CreateThreads() { boost::thread t1( boost::bind( &TestThread::thread, 10)); boost::thread t2( boost::bind( &TestThread::thread, 20));
The ::thread method is non-static, and you don't pass any object to bind. You should have boost::bind (&TestThread::thread, some_object, 10) HTH, Volodya