Some questions I asked yesterday were interrupted. I only have some questions with boost library...
coder777 :
I still believe void* definition can be anything. So, a few questions :
- Can the boost function member variable be converted into a void* address value?
- Is the boost variable a structure or a number?
- Could you please show me an example "How to get (copy) the address of the function member, store the result into a void* then print the output function address properly?" :)
#include <iostream>
int test(int a, int b) {
return a + b;
}
/* I would NEVER do this in practice */
int example(constvoid* blob) {
int(**pFunc)() = (int(**)())(blob);
return (*pFunc)();
}
int main() {
int(*lamFunc)() = []() -> int{ return test(1, 2); };
std::cout << "Output: " << example(static_cast<void*>(&lamFunc)) << std::endl;
/* I feel dirty. */
}
Of course, you can use bind to bind instances to member functions instead of using a lamda.
2. Boost Variable? I'm not sure what you mean unless you mean the variant.
Yeah, I see your solution, and I've just searched your new function definition :
int(*lamFunc)()
Great! It's much simpler than template. A great invention!!!!!!!
And more importantly, the variable is completely able to be converted into an address value. I'll only need to declare a void* variable, define an another function variable which must correspond with the function member's syntax, then store the member address. Finally convert it into a void*. See this :