Say I have the following code:
class A
{
public:
A() {}
int f(void*, void*)
{
return 0;
}
};
template <typename T>
class F {
public:
F(int(T::*f)(void*,void*))
{
this->f = f;
}
int(T::*f)(void*,void*);
int Call(T& t,void* a,void* b)
{
return (t.*f)(a,b);
}
};
A a;
F<A> f(&A::f);
f.Call(a, 0, 0);
Well this works I can call the function easily but how would I for example have an array of these without knowing the type?
I would like to be able to call any class f function as a callback. I'd normally use a static or c function and be done with it but I wanted to experiment with calling a C++ member function.
Think of what I'm trying to do as delegates in C#. I've seen very sophisticated implementations in Boost and other places but I want the bare minimum, no copying, creation, deletion etc required just a simple callback that I can call.
Is this a pipedream? Any advice would be appreciated.