I tried this code and it seems to check out when i type it into cdecl.org but the function "dbl" gives me a compile error when i try to return a pointer to an array of function pointers. Am I defining "fp" right?
#include <iostream>
#include <cassert>
using namespace std;
#define DEF(X) double * X(int y) { \
double z = (double)3.55+y; \
double * ptr = &z; \
cout << "inside func " #X << ". Returning a dbl ptr with *ptr value of " \
<< *ptr << endl; return ptr;}
DEF(a); DEF(b); DEF(c);
/*
a pointer to an array of 3 pointers to functions that take an int and return a double
pointer
*/
double * (*fp[])(int) = {a,b,c};
/*
pointer to function that takes an int
and returns a pointer to a function that takes a double ptr and returns a pointer
to an array of 3 pointers to functions that take an int and return a double
pointer
*/
double * (*(*(*(*f1)(int))(double *))[3])(int);
/*
a function that takes a double ptr and returns a pointer
to an array of 3 pointers to functions that take an int and return a double
pointer
*/
double * (*(*dbl(double *))[3])(int)
{
cout << "inside dbl" << endl;
return fp;
}
/*
function that takes an int
and returns a pointer to a function that takes a double ptr and returns a pointer
to an array of 3 pointers to functions that take an int and return a double
pointer
*/
double *(*(*(*func(int))(double *))[3])(int)
{
cout << "inside func" << endl;
return dbl;
}
int main()
{
/*
char choice = 'c';
double * ptr;
ptr = (*fp[choice - 'a'])(5);
assert(ptr != NULL);
*/
cin.get();
}
This is the error it gives lol.....
cannot convert from 'double *(__cdecl *[3])(int)' to 'double *(__cdecl *(*)[3])(int)
-edit- i dont think fp is actually a "pointer to an array of function pointers" but its just an "array of function pointers". But I don't know how to make it an actual pointer, I keep getting errors.