When Syntax attacks.
Ok, so I’ve got a bizarre situation in C++, whereby two objects on two different threads want to run methods on each other.
My solution is to have a public interface which packages up the details of the function call in a struct and sends a message to the thread asking to invoke the function.
So I’ve got a nice struct with a function pointer in and all the arguments in. I wanted to have a vector or a queue or some-such so that I could have a generic container and put the function pointer in first and the arguments in in order – but C++ doesn’t like so many different types in an array so I’ve got a struct for each combination of arguments. Fortunately they’re all void func(void) functions so no worries.
However, calling the function at the other end is a marvellous example of syntax gone mad. Here’s the call. The pointer to the Invocation object has to be passed as an LPARAM, as windows messages suck.
(this->*((Invocation*)pL)->pFunc)();
I ended up almost moving brackets and asterisks around at random to get the correct line. I had assumed it would be:
(*(this->((Invocation*)pL)->pFunc))();
But that didn’t seem to work. Sigh…
And for the curious, can you tell me why this won’t work if it’s ported to windows x64 (it’ll work on Win64 as it is though).
Recent Comments