Archived

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

C++ Function Pointer Question

This topic is 5538 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

I’ve just run into a C++ problem I haven’t encountered before using function pointers. I wanted to use a function pointer to call a public function in another class, and I’ve got something similar to the below code to set the function pointer: bool (COtherClass::*FuncPt) (int); if (Condition) FuncPt = COtherClass::Function1; else FuncPt = COtherClass::Function2; This compiles and links fine. The problem comes when trying to call the function pointer to by FuncPT because I don’t know the syntax to call it. I’ve tried all of the a few ways like the ones below but they all produce errors OtherClassObjPt->FuncPt(iIntvar); OtherClassObjPt->*FuncPt(iIntvar); OtherClassObjPt->(*FuncPt)(iIntvar); Can anyone tell me how to use function pointers to call a public function in another class? Thanks a lot. [edited by - mjones0 on October 18, 2002 10:52:59 AM]

Share this post


Link to post
Share on other sites