views:

50

answers:

2

hello, i need to use the function in another class file as thread

int main()
{
master t;

boost::thread t1(boost::bind(t.start, "exampl"));

t1.join();
}

i have an class master and a function start ..i need to pass an value to it and run i have used this in same class it works fine...can any one tell me where i am wrong

+7  A: 

You need to bind the member function to the instance:

boost::thread t1(boost::bind(&master::start, t, "exampl"));
James McNellis
The OP might want to write `boost::thread t1(boost::bind(
Doug
A: 

James's solution will have your master object copied. If you want to sort of pass by reference, then

boost::thread t1(boost::bind(&master::start, &t, "exampl"));

HTH

Armen Tsirunyan