• Advertisement

Archived

This topic is now archived and is closed to further replies.

Pointer to a Function?

This topic is 5214 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is it possible to pass a name/pointer of a function through a method so that the method can call the function? Example:
int *foo()
{
    return 5;
}

int fooMethod(int *function())
{
    // Call the function passed through
    function();
    return 0;
}

int main()
{
    // Call the foo method passing through the foo function.
    fooMethod( foo() );
    return 0;
}
   
..... Is it possible to do that some how? I know this example seems a bit usless, but what I'm using it for would just make the program kick ass. [edited by - Rob Loach on November 17, 2003 10:06:18 PM]

Share this post


Link to post
Share on other sites
Advertisement
In C and C++ it is completely possible to do this. Here's how.

Edit: Too late...

[edited by - GreenToad on November 17, 2003 11:17:40 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Namethatnobodyelsetook
Yes. Changed your sample to int from int *, since you''re not returning an int *... [ code ]
Also click here



Awesome! Thanks a lot!

Hmmm, they make it WAY more complicated then it actually is.

Share this post


Link to post
Share on other sites

  • Advertisement