//
typedef int (*FUNCPTR)(int a, int b);
{
return a + b;
}
{
return a - b;
}
// define the class function pointer type
typedef int (MyMathUtil::*CLS_FUNC_PTR)(int a, int b);
{
public:
int Add(int a , int b) { return a + b;}
int Sub(int a , int b) { return a - b;}
{
int r;
r = (this->*m_pFuncPtr)(a, b);
return r;
}
CLS_FUNC_PTR m_pFuncPtr;
};
{
FUNCPTR ptr = NULL;
ptr = &Add; //or: ptr = Add; directly
int r = (*ptr)(1, 2);
CLS_FUNC_PTR clsFuncPtr = NULL;
clsFuncPtr = &MyMathUtil::Add; // Here, we must use &
r = mathUtil.Operation(1, 2); // It can work like this
}