Seems like a crazy at the first instance, but this is an amazing use of the facility provided by C++ which is called, pointer to member of a class. This can be a function or a variable. But where to use it. Well one of cases is when one needs to call different function of same signature based on some parameter. Surely this can be done via other trivial means as well certain situation may call for special measures. This can used in that case.
How to create and use it is taken straight out of C++ FAQLite . Link to specific page is here.
Say we have a class A as following
class A
{
public :
void a(int x);
void b(int x);
void c(int x);
void d(int x);
}//create array of pointer to member function
int ((A::*ptr)[4])(int x) = {&A::a, &A::b, &A::c, &A::d};//using it in function
void testFunc(int val1, int val2)
{
ObjectOfA.*(ptr[val1])(val2);
}
So our testfunction will call a,b,c or d from ObjectOfA depending on the val1 with parameter val2. Though obviously there are better ways to do it, but then this is also one complicated but shorter(codewise) one.