The constructor for such objects requires the following:
The member functions must return void and accept no parameters.
Example
class MyClass {
public:
void job() {
// Code to run on separate thread.
}
};
MyClass *myObj;
myObj = new MyClass;
INonGUIThread thread;
thread.start( new IThreadMemberFn( *myObj, MyClass::job ) );
You can add support for other type of member functions by deriving a class from IThreadFn.
Example 2
class Foo {
public:
void job(int a, double b, Foo* other) {
// Code to run on separate thread.
}
};
class IFooFn : public IThreadFn
{
public:
typedef void (Foo::* func_t)(int, double, Foo*);
FooFn(Foo& f, func_t fn, int a, double b, Foo* o)
: foo(f), func(fn), _a(a), _b(b), _o(o) {}
virtual void run() {
(foo.*func)(_a, _b, _o);
}
private:
Foo& foo;
func_t func;
int _a;
double _b;
Foo* _o;
}
Foo *foo = new Foo();
INonGUIThread thread;
thread.start( new IFooFn(*foo, &Foo::job, 1, 1.0, foo) );
Constructors & DestructorUse these members to construct and destruct objects of this template class.
![]() |
public:
virtual ~IThreadMemberFn()
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
![]() |
public:
IThreadMemberFn(T& obj, void ( T::* mem ) ( ))
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
Run FunctionUse these members to run the member function that was specified when an object of this class was created.
![]() |
public:
virtual void run()
| Windows | OS/2 | AIX |
| Yes | Yes | Yes |
virtual ~IThreadFn()
IThreadFn()
virtual void run() = 0