libcommonc++
0.7
|
An adapter object that implements the Runnable interface and delegates to an arbitrary method (one that must have no arguments or return value) in some other object. More...
#include <Runnable.h++>
Public Member Functions | |
RunnableDelegate (T *object, void(T::*func)()) | |
Construct a new RunnableDelegate which will call a method on another object. More... | |
void | run () |
Entry point. More... | |
An adapter object that implements the Runnable interface and delegates to an arbitrary method (one that must have no arguments or return value) in some other object.
This allows a class to have multiple methods that will execute asynchronously in their own threads. For example, consider the class:
class MyClass { public:
MyClass(); ~MyClass();
void thread1(); void thread2(); };
Given an instance of MyClass, the following construct causes a new thread to begin executing in the thread1() method of that instance.
MyClass mc;
RunnableDelegate<MyClass> runnable(&mc, &MyClass::thread1); Thread thread(&runnable); thread.start();
|
inline |
Construct a new RunnableDelegate which will call a method on another object.
object | The object. |
func | A member function (method) in the object which will be called by run(). |
|
inlinevirtual |
Entry point.
Implements Runnable.