I have a worker thread, which holds a list of 'Thread Actions', and works through them as an when.
template <class T> class ThreadAction
{
public:
typedef void (T::*action)();
ThreadAction(T* t, action f) :
func(f),obj(t) {}
void operator()() { (obj->*func)(); }
void (T::*func)();
T* obj;
};
It's normally called like this
myActionThread->addAction(
new ThreadAction<TheirClass>(this, &TheirClass::enable)
);
Which worked fine until
void TheirClass::enable()
was changed to
bool TheirClass::enable()
Sadly we can't change it back again because other stuff needs the new format, (and overloads can't differ by return type alone).
I did try
myActionThread->addAction(
new ThreadAction<TheirClass>(this,
reinterpret_cast<void(TheirClass::*)>(&TheirClass::enable)
)
);
Which appears to work just fine, but I'm not certain that reinterpreting a function pointer like this is 'defined' behaviour, can somebody please advise?