• Announcements

Archived

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

C++ Function Pointer Question

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 on other sites
(OtherClassObjPt->*FuncPt)(iIntvar);

Share on other sites
Thanks a lost! I didn''t think to put the braces there

Share on other sites
quote:
Original post by mjones0
Thanks a lost! I didn''t think to put the braces there

Parentheses. Braces are used for holding your trousers up.

• Partner Spotlight

• Forum Statistics

• Total Topics
627637
• Total Posts
2978336

• 10
• 12
• 22
• 13
• 33