Protoman said:
How would you write a function returning a function pointer and why
would you need to do this? Is it:
int(*)(int&) fn(int& arg);
Thanks!!!
Given a function
int foo(int &x)
{
++x;
return x;
}
a function that takes an int reference parameter arg and will return a
pointer to foo takes the form
int (*fn(int& arg))(int &)
{
return &foo; // the & is optional
}
However, you will give yourself less brain strain if you do it this way:
typedef int (*fnptr)(int&);
fnptr fn(int& arg)
{
return &foo;
}
As for why you would need to do this, perhaps fn would select the
appropriate function pointer the program needs to use, based on the
calculations it does with arg.