home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / cplus / 19877 < prev    next >
Encoding:
Text File  |  1993-01-25  |  1.4 KB  |  48 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!pmafire!mica.inel.gov!ux1!fcom.cc.utah.edu!swillden
  3. From: swillden@news.ccutah.edu (Shawn Willden)
  4. Subject: Re: References to functions?
  5. Message-ID: <1993Jan25.182507.13761@fcom.cc.utah.edu>
  6. Sender: news@fcom.cc.utah.edu
  7. Organization: University of Utah Computer Center
  8. X-Newsreader: Tin 1.1 PL3
  9. References: <1k0d3dINNev9@info2.rus.uni-stuttgart.de>
  10. Date: Mon, 25 Jan 93 18:25:07 GMT
  11. Lines: 35
  12.  
  13. KOCHER@nvdv.e-technik.uni-stuttgart.dbp.de (HARTMUT KOCHER) writes:
  14. : > References to functions are legal, but not very useful.  I can't
  15. : > think of anything you can do with a reference to a function you
  16. : > can't do with a const pointer to a function in exactly the same way,
  17. : > except for trivial syntax differences at the point of initialization.
  18. : > You use them in exactly the same way.
  19. : > 
  20. : > stuff deleted
  21. : -- 
  22. : > 
  23. : > Steve Clamage, TauMetric Corp, steve@taumet.com
  24. : Not exactly. Let's say I have a callback class which takes a pointer
  25. : to a function in its constructor. If I use a pointer, a 0-pointer may be
  26. : passed. If I use a reference instead, I can make sure, that the user
  27. : supplies a valid function.
  28.  
  29. Not really.  Try:
  30.  
  31. typedef int (callbackfunc)(int);
  32.  
  33. extern void set_callback(callbackfunc&);
  34.  
  35. void foo()
  36.     {
  37.     callbackfunc* callback = 0;
  38.  
  39.     set_callback(*callback);
  40.     }
  41.  
  42. : Hartmut Kocher
  43.  
  44. --
  45. Shawn Willden
  46. swillden@icarus.weber.edu
  47.