C++ Function Pointer Question

Started by
2 comments, last by mjones0 21 years, 6 months ago
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]
Advertisement
(OtherClassObjPt->*FuncPt)(iIntvar); 
Thanks a lost! I didn''t think to put the braces there
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.

This topic is closed to new replies.

Advertisement