Using Boost 1.43 threads, the following is compilable:
void MyClass::threadFn(...) { ... }
void MyClass::doFn(...) {
...
boost::thread(&MyClass::threadFn, this, ...);
}
But the following is not compilable:
void MyClass:doFn(...) {
...
struct MyStruct {
MyStruct(...) { ... };
}
boost::thread(&MyStruct, ...);
}
This yields 'MyClass::doFn::MyStruct': illegal use of this type as an expression
. Note that I am not trying to pass a pointer to an instance of MyStruct
; I am trying to pass the type itself, as I would a function pointer, so that boost::thread
will invoke the constructor of the type.
According to The Boost 1.43 Threads Spec:
A new thread is launched by passing an object of a callable type
So how do I pass the address of the struct
type to the boost::thread
function (AFAIK this would also apply to boost::bind
)?