I need to implement a pointer to a function that returns a pointer. That should be easy, like:
typedef int* (*ptrInt)(const int);
ptrInt ptFunc;
And then,
int* foo(const int a) {
int* b = new int[a];
return b;
}
int main(void){
ptrInt ptFunc = foo;
int *c = foo(2);
return 0;
}
That is correct and I tried already, but I am writing a code and I have the following:
typedef double* (*ptrFunc)(const double);
class Test{
protected:
ptrFunc ptF;
double* f1(const double);
double* f2(const double);
public:
Test(const int opt){
if (opt == 1) ptF = f1;
else ptF = f2;
};
I get an error message saying that:
argument of type ‘double* (testenamespace::Test::)(double)’ does not match ‘testenamespace::ptrFunc {aka double* (*)(double)}’ test1.hpp
Any idea of what is going on?
Thank you in advance!