Currently I have created a class called A that creates an array of pointers to functions as well as declared the function's prototypes, please view the A.h below.
#ifndef A_H
#define A_H
class A
{
public:
//Function Definitions that will be called from the seq function below.
A::A()
//prototype functions that will be pointed to from array
void f1(int);
void f2(int);
void f3(int);
void (*funcs[3])(int);
//Destructor method
virtual ~A();
};
Then I have A.cpp defined below with the function definitions of f1, f2, f3.
A::A()
{
}
void A::f1(int a){ cout << "This is f1: " << endl; }
void A::f2(int b){ cout << "This is f2: " << endl; }
void A::f3(int c){ cout << "This is f3: " << endl; }
//Would this be valid?
funcs[0] = f1;
funcs[1] = f2;
funcs[2] = f3;
A::~A()
{
//dtor
}
How would I access the array from main.cpp
include "A.h"
.
.
.
int main()
{
//This doesn't work, what is the proper way to access the pointers to functions?
A a;
a.funcs[0](1);
}
Should print out "This is f1: ". This has really been bugging me, i've been reading different threads and even used typedefs but to no avail. Any help would truly be appreciated. If you need anymore details please let know.