home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 13067 < prev    next >
Encoding:
Internet Message Format  |  1992-08-30  |  2.2 KB

  1. Path: sparky!uunet!charon.amdahl.com!pacbell.com!att!linac!pacific.mps.ohio-state.edu!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!rpi!gatech!bloom-beacon!eru.mt.luth.se!lunic!sunic!liuida!isy!isy.liu.se!svan
  2. From: svan@isy.liu.se (Jonas Svanberg)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Callbacks - C++ needs an extension?
  5. Keywords: callback
  6. Message-ID: <1992Aug30.180248.1700@isy.liu.se>
  7. Date: 30 Aug 92 18:02:48 GMT
  8. References: <1893@acf5.NYU.EDU>
  9. Sender: news@isy.liu.se (Lord of the News)
  10. Reply-To: svan@isy.liu.se
  11. Organization: Linkoping University
  12. Lines: 45
  13.  
  14. I acknowledge checker@acf5.NYU.EDU (checker) for a nice solution
  15. to the callbackproblem:
  16.  
  17. Every class that want to receive direct callbacks must declare an
  18. own callback class which inherits from some sort of systemclass
  19. CallBack or whatever. In this derived class one defines a new
  20. constructor and overloads one memberfunction. These new member-
  21. functions contain typinginformation about the receiver of the 
  22. callback, so this will work and it is safe. 
  23.  
  24. This can be nicely done with templates I suppose, but it still
  25. seems like hard work to me.
  26.  
  27. I have got another solution in comp.windows.open-look from 
  28. imp@solbourne.com (Warner Losh):
  29.  
  30. > In OI, you can regstier a C or a C++ style callback.  Just an
  31. > overloaded call.  For example,
  32. >    OI_menu_cell *cellp;
  33. >    MyClass         *mcp;
  34. >
  35. >    // call ::foo when button activated.
  36. >    cellp->change_action( &foo );
  37. >
  38. >    // call MyClass::bar when button activated
  39. >    cellp->change_action( mcp, (OI_action_memfnp) &MyClass::bar );
  40.  
  41. My presumption is that the type OI_action_memfnp is a pointer-to-member-of-
  42. -baseclass-of-MyClass. My question is:
  43.  
  44. Is it safe to make the call (obj->*membfun)() when both the obj* (of class
  45. A) and the membfun* have been casted from respectively:
  46. 1. a pointer to a class derived from A and (the obj*)
  47. 2. a pointer to a member of a class derived from A (the memfun*)
  48. ?
  49.  
  50. Cast #1 above can be done implicitely of course, but #2 has to be
  51. done explicitely if I have understood things correctely...
  52.  
  53. --------------------------------------------------------------
  54.  Jonas Svanberg
  55.  Department of Electrical Engineering
  56.  Linkvping University
  57.  S-581 83 Linkvping, Sweden             Email: svan@isy.liu.se
  58. --------------------------------------------------------------
  59.