In A.h:
class A
{
typedef void (A::*fp)();
void test1();
void test2();
A(int a);
}
In A.cpp I have:
A::A(int a)
{
fp fpointers[] = {&A::test1,&A::test2};
fpointers[a]();
}
void A::test1()
{
//do something
}
void A::test2()
{
//do something
}
This is a reduced and simplified version of what I have. But the problem is still valid. From my humble experience 'fpointers' is how you define and declare an array of function pointers. I am having problem with line fpointers[a]();I am getting this error:
expression preceding parentheses of apparent call must have (pointer-to-) function type
What am I doing wrong?
std::function. Bit more runtime overhead, but cleans up some of the messiness of method pointer syntax. Especially interesting with lambda expressions andstd::bind.