Boost logo

Boost :

Subject: [boost] To create a boost thread
From: Filip Klasson (filkl784_at_[hidden])
Date: 2009-03-12 12:00:29


Hi,

I have problems creating a thread.
This is an example i found:

#include <boost/thread/thread.hpp>
#include <iostream>

void hello() { std::cout << "Hello world, I'm a thread!" << std::endl; }

int main(int argc, char* argv[]) {

boost::thread thrd(&hello);

thrd.join();

return 0;

}
What if i want to create a thread outside of main (in a class) like this:
"myClass.h"

class MyClass {
public:
hello();
myFunction();
};

"myClass.cpp"
MyClass::hello() {
std::cout << "Hello world, I'm a thread!" << std::endl;
}

MyClass::myFunction() {
boost::thread thrd(&hello);
thrd.join();
}

This does not work and i get the compile error: '&' : illegal operation on
bound member function expression


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk