///to implement an array of class member function pointers, see the code below, and also note that static array members can not declare array size within a class
class Cmymath
{
Public:
int ADD (int A, int b);
int Sub (int a, int b);
///matharr is an array in which the array holds the pointer, and the pointer is the function pointer
///function is a Cmymath class member function
///So Matharr is an array of Cmymath class member function pointers,
static int (cmymath::* matharr[]) (int, int); br> int Calc (void);
};
implementation of///array
Int (cmymath::* (cmymath::matharr[])) (int, int) =
{
&cmymath::add,
&cmymath::sub,
NULL,
};
int Cmymath::add (int a, int b)
{
return a+b;
}
int cmymath::sub (int a, int b)
{
return a-b;
}
int Cmymath::calc ()
{
Class called Outside the class call, which is called directly from the
Return (This->*matharr[0]) (10, 30);
}
Cmymath Math;
Call within the class
int c = Math. Calc ();
class, because the function is a function within the class, so add the class's variable name to the pointer before calling it math
c = (math.* (cmymath::matharr[1])) (50, 9);