I am trying to understand the syntax to call the function through a pointer to an array of function pointers.
I have array of function pointers FPTR arr[2], and a pointer to this array FPTR (vptr)[2] . But it gives me an error when trying to call through the pointer to an array
typedef int (*FPTR)();
int func1(){
cout<<"func1() being called\n";
}
int func2(){
cout<<"fun2() being called\n";
}
FPTR arr[2] = {&func1,&func2};
FPTR (*vptr)[2];
vptr=&arr;
cout<<"\n"<<vptr[0]<<endl;
cout<<"\n"<<vptr[0]()<<endl; // ERROR when trying to call the first function
vptris pointer, so first you should dereference it before accesing elements of array pointed to by it:(*vptr)[0]().(*vptr)[0]prints 1 always no matter for[0]or[1]or any other element of an array. Sameways,cout<<func1orcout<<&func1also prints 1 alwaysvoid*otherwiseostream::operator<<(bool)is called.cout<<"\n"<< (void*)(*vptr)[0]<<endl;