Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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!

share|improve this question
1  
possible duplicate of How do you pass a member function pointer? – icepack Jul 16 at 21:26

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.