I want to create a callback system that can call back (member or non-member) functions that take (int, ...) as parameters and return void. For this to work, it must be possible to create an array of function pointers where every index of the array may contain either a member or non-member function with the specified parameters and returntype. And it must be possible to call the functions without knowing if it is a member function or not.
Here is some pseudocode to explain my idea:
Code:
// flexibleFunctionType is a type that can store function pointers and pointer-to-member functions
flexibleFunctionType funcArray[100];
class X {void foo(int, ...);};
X x;
void bar(int, ...);
// Syntax probably wouldn't look like that, but the following means:
// funcArray now contains a pointer to the member function "foo",
// that is invoked on the object "x".
funcArray[10] = &x.foo;
// Store a normal function pointer to function bar:
funcArray[20] = &bar;
(*(funcArray[10])) (1, 5); // Calls: x.foo(1, 5);
(*(funcArray[20])) (2, 10, 67); // Calls: bar(2, 10, 67);
// BTW, the above calls use literal values, but it is not required that that is possible.
I've looked at boost::function and boost::bind, but I found it somewhat difficult to understand and I don't know if this could be a solution. I still consider myself a newbie in C++, so please explain in simple terms.
Thanks