home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!pmafire!mica.inel.gov!ux1!fcom.cc.utah.edu!swillden
- From: swillden@news.ccutah.edu (Shawn Willden)
- Subject: Re: References to functions?
- Message-ID: <1993Jan25.182507.13761@fcom.cc.utah.edu>
- Sender: news@fcom.cc.utah.edu
- Organization: University of Utah Computer Center
- X-Newsreader: Tin 1.1 PL3
- References: <1k0d3dINNev9@info2.rus.uni-stuttgart.de>
- Date: Mon, 25 Jan 93 18:25:07 GMT
- Lines: 35
-
- KOCHER@nvdv.e-technik.uni-stuttgart.dbp.de (HARTMUT KOCHER) writes:
- : > References to functions are legal, but not very useful. I can't
- : > think of anything you can do with a reference to a function you
- : > can't do with a const pointer to a function in exactly the same way,
- : > except for trivial syntax differences at the point of initialization.
- : > You use them in exactly the same way.
- : >
- : > stuff deleted
- : --
- : >
- : > Steve Clamage, TauMetric Corp, steve@taumet.com
- :
- : Not exactly. Let's say I have a callback class which takes a pointer
- : to a function in its constructor. If I use a pointer, a 0-pointer may be
- : passed. If I use a reference instead, I can make sure, that the user
- : supplies a valid function.
-
- Not really. Try:
-
- typedef int (callbackfunc)(int);
-
- extern void set_callback(callbackfunc&);
-
- void foo()
- {
- callbackfunc* callback = 0;
-
- set_callback(*callback);
- }
-
- : Hartmut Kocher
-
- --
- Shawn Willden
- swillden@icarus.weber.edu
-