home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 18005 < prev    next >
Encoding:
Text File  |  1992-12-15  |  1.9 KB  |  56 lines

  1. 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
  2. From: doug@foxtrot.ccmrc.ucsb.edu (Douglas Scott)
  3. Newsgroups: comp.lang.c++
  4. Subject: Calling a member functn via ptr passed as arg to another functn
  5. Message-ID: <7138@ucsbcsl.ucsb.edu>
  6. Date: 15 Dec 92 04:46:35 GMT
  7. Sender: news@ucsbcsl.ucsb.edu
  8. Organization: Center for Computer Music Research and Composition, UCSB
  9. Lines: 45
  10.  
  11. Here is a very much simplified case of what I wish to do:
  12.  
  13. class Object;    // to allow typedef
  14. typedef int (*Object::InternalFun)(int); // or close to this...
  15.  
  16. class Object {
  17.     int internalFunctionA(int i);
  18.     int internalFunctionB(int i);
  19.  
  20.     int anotherFunction(int x, InternalFun funptr);
  21. public:
  22.     int pubFunA(int x) { return anotherFunction(x, internalFunctionA); }
  23.     int pubFunB(int x) { return anotherFunction(x, internalFunctionB); }
  24. };
  25.  
  26. // trivial cases of these...
  27.  
  28. int Object::internalFunctionA(int i) { return i * 5; }
  29.  
  30. int Object::internalFunctionB(int i) { return i * 6; }
  31.  
  32. int Object::anotherFunction(int x, InternalFun funptr) {
  33.     return (*funptr)(x);    // this is obviously wrong
  34. }
  35.  
  36. What I wish to do is create a series of public functions that all call a
  37. single private function, with the difference being that pointers to various
  38. other internal functions are passed as the second argument.
  39.  
  40. I dont have my ARM handy, so I may have the declaration of the typedef wrong,
  41. but my question relates to the final function definition:
  42.  
  43. How do I call funptr within anotherFunction()?  Something like:
  44.  
  45. this->(*funptr)(x) ??  (*this->funptr)(x) ??
  46.  
  47. -- perhaps??  I have not been able to come up with the correct one yet.
  48.  
  49. Thank you very much in advance.
  50.  
  51. -- 
  52. Douglas Scott                              (805)893-8352
  53. Center for Computer Music Research and Composition
  54. University of California, Santa Barbara
  55. Internet: (NeXTMail ok)   <doug@foxtrot.ccmrc.ucsb.edu>
  56.