I'm running into some issues with boost::bind and creating threads.
Essentially, I would like to call a "scan" function on a "Scanner" object, using bind.
Something like this:
Scanner scanner;
int id_to_scan = 1;
boost::thread thr1(boost::bind(&scanner::scan));
However, I'm getting tripped up on syntax. How do I pass the data into scan? As part of the constructor?
Keep in mind that the first argument to any member function is the object.
So if you wanted to call:
scanner* s;
s->scan()
with bind you would use:
boost::bind(&scanner::scan, s);
If you wanted to call:
s->scan(42);
use this:
boost::bind(&scanner::scan, s, 42);
Since I often want bind to be called on the object creating the bind object, I often do this:
boost::bind(&scanner::scan, this);
Good luck.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With