home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 13180 < prev    next >
Encoding:
Text File  |  1992-09-01  |  2.0 KB  |  58 lines

  1. Path: sparky!uunet!usc!rutgers!cmcl2!acf5!checker
  2. From: checker@acf5.NYU.EDU (checker)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Callbacks - C++ needs an extension?
  5. Keywords: callback
  6. Message-ID: <1895@acf5.NYU.EDU>
  7. Date: 2 Sep 92 04:58:58 GMT
  8. References: <1893@acf5.NYU.EDU> <1992Aug30.180248.1700@isy.liu.se>
  9. Organization: New York University
  10. Lines: 46
  11.  
  12. svan@isy.liu.se (Jonas Svanberg) writes:
  13. >Every class that want to receive direct callbacks must declare an
  14. >own callback class which inherits from some sort of systemclass
  15. >CallBack or whatever. In this derived class one defines a new
  16. >constructor and overloads one memberfunction. These new member-
  17. >functions contain typinginformation about the receiver of the 
  18. >callback, so this will work and it is safe. 
  19. >This can be nicely done with templates I suppose, but it still
  20. >seems like hard work to me.
  21.  
  22. When the original template classes are done correctly, there is very
  23. little work (either real or conceptual) to be done:
  24.  
  25. // assume the correct templates are written
  26.  
  27. class button
  28. {
  29. public:
  30.     button( callback3<int,int,int> &CB );
  31. };
  32.  
  33. This means button takes a callback that takes three ints.  To call it, I
  34. do this:
  35.  
  36. specific_callback3<my_class,int,int,int> cb(*this,&my_class::Func);
  37.  
  38. button B(cb);
  39.  
  40. All of the derivation and crud is already done in the template classes. 
  41. The two lines above are the only things you ever need to write once the
  42. original templates are debugged (and they're pretty simple, too).  I
  43. should stop to give credit where credit is due, a friend of mine (Rich
  44. Hickey) came up with the template extension to this scheme; the original
  45. used nested classes.
  46.  
  47. >Is it safe to make the call (obj->*membfun)() when both the obj* (of class
  48. >A) and the membfun* have been casted from respectively:
  49. >1. a pointer to a class derived from A and (the obj*)
  50. >2. a pointer to a member of a class derived from A (the memfun*)
  51. >?
  52.  
  53. I'd have to see the full declarations, but most of these casting schemes
  54. break badly under multiple inheritance.  There are ways to do it without
  55. casting so they should be used.
  56.  
  57. Chris
  58.