
functions returning pointers to functions
Quote:
> Hi,
> I've come across a problem trying to define a function that returns a
> pointer to another function type (without using typedefs :).
> I've come up with the following which I thought would have been right,
> but it's not!
> int (*)(int) func(void)
> {
> ...
> }
> Here, func should return a pointer to a function taking an int as
> a parameter and returning an int. Is there any way to do this, or
> do you have to use typedefs?
Take it one step at a time. For these kinds of problems, I work from
the outside in.
1. int f (int x) -- f is a function taking one int parameter
and returning an int
2. f = (*g) -- g is a pointer. Substitute for f in (1) to get
int (*g)(int x). g is a pointer to a function
taking one int parameter and returning an int.
3. g = h(void) -- h is a function. Substitute for g in (2) to get
int (*h(void))(int x). h is a function which
takes no parameters and returns a pointer to a
function which takes one int parameter and
returns int.
Hope the derivation makes sense. It's a lot easier on everyone to just
use typedefs, though.
--
www.biggerhammer.com | Low Technology Solutions for
| High Technology Problems
Sent via Deja.com http://www.deja.com/
Before you buy.