home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbnewse!cbnewsd!att-out!walter!qualcom.qualcomm.com!network.ucsd.edu!ucsbcsl!foxtrot!doug
- From: doug@foxtrot.ccmrc.ucsb.edu (Douglas Scott)
- Newsgroups: comp.lang.c++
- Subject: Calling a member functn via ptr passed as arg to another functn
- Message-ID: <7138@ucsbcsl.ucsb.edu>
- Date: 15 Dec 92 04:46:35 GMT
- Sender: news@ucsbcsl.ucsb.edu
- Organization: Center for Computer Music Research and Composition, UCSB
- Lines: 45
-
- Here is a very much simplified case of what I wish to do:
-
- class Object; // to allow typedef
- typedef int (*Object::InternalFun)(int); // or close to this...
-
- class Object {
- int internalFunctionA(int i);
- int internalFunctionB(int i);
-
- int anotherFunction(int x, InternalFun funptr);
- public:
- int pubFunA(int x) { return anotherFunction(x, internalFunctionA); }
- int pubFunB(int x) { return anotherFunction(x, internalFunctionB); }
- };
-
- // trivial cases of these...
-
- int Object::internalFunctionA(int i) { return i * 5; }
-
- int Object::internalFunctionB(int i) { return i * 6; }
-
- int Object::anotherFunction(int x, InternalFun funptr) {
- return (*funptr)(x); // this is obviously wrong
- }
-
- What I wish to do is create a series of public functions that all call a
- single private function, with the difference being that pointers to various
- other internal functions are passed as the second argument.
-
- I dont have my ARM handy, so I may have the declaration of the typedef wrong,
- but my question relates to the final function definition:
-
- How do I call funptr within anotherFunction()? Something like:
-
- this->(*funptr)(x) ?? (*this->funptr)(x) ??
-
- -- perhaps?? I have not been able to come up with the correct one yet.
-
- Thank you very much in advance.
-
- --
- Douglas Scott (805)893-8352
- Center for Computer Music Research and Composition
- University of California, Santa Barbara
- Internet: (NeXTMail ok) <doug@foxtrot.ccmrc.ucsb.edu>
-