I need an array to hold member-function-pointers of different classes. How can I define the array?
The code should look like this:
arr[0] = &CMyClass::FuncX;
arr[1] = &CYourClass::FuncY;
arr[2] = &CHerClass::FuncZ;
I tried void*, but it doesn’t work.
You can’t; they are all different types and arrays are homogeneous.
Regardless what the arguments are or what the return value is, there is an implicit
thiswhich is unique to the class type. The type of a class member pointer is:As you can see, because they belong to different classes they will always be a different type. Even if it were the same class, the
return_valueandparameterswould have to be consistent to create an array, otherwise you’d still have different types.What’s the bigger picture? Boost.Bind with Boost.Function comes to mind. Also, virtual functions may solve your problem.