home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 16049 < prev    next >
Encoding:
Text File  |  1992-11-10  |  1.1 KB  |  34 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!think.com!ames!decwrl!csus.edu!netcom.com!dx
  3. From: dx@netcom.com (dx)
  4. Subject: Invoking functions passed as parameters
  5. Message-ID: <1992Nov10.192709.682@netcom.com>
  6. Organization: Netcom - Online Communication Services  (408 241-9760 guest) 
  7. Date: Tue, 10 Nov 1992 19:27:09 GMT
  8. Lines: 24
  9.  
  10. In standard C, function pointers passed as paramters are invoked with
  11. the standard C syntax, e.g.,
  12.  
  13.     foo(void (*pf)(parmeters))
  14.     {
  15.         pf(paremeters)
  16.     }
  17.  
  18. Now suppose I have a class PFCLASS, and pf points to a member function of
  19. this class, and within foo I want to apply the method pointed to by pf to
  20. an instance of PFCLASS, pointed to by pInstance.
  21.  
  22. In standard C syntax, I would make the member function take the pointer to
  23. the instance as a parameter, and use the standard way to call the function:
  24.  
  25.     pf(pInstance);
  26.  
  27. But I wonder if there is some way to invoke the method pointed to by pf
  28. in a more C++ like way, such that pInstance turns up as the 'this' pointer
  29. in the method, rather than having to pass it as a parameter.
  30.  
  31. Any ideas?
  32.  
  33. -dx
  34.