home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.std.c++
- Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
- From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
- Subject: Re: C++ already *has* nested functions SO WHAT'S THE BEEF?
- Message-ID: <9300811.3521@mulga.cs.mu.OZ.AU>
- Keywords: nested functions, dumb ideas
- Sender: news@cs.mu.OZ.AU
- Organization: Computer Science, University of Melbourne, Australia
- References: <1992Dec21.080952.15309@netcom.com> <harvey.726175866@regina>
- Date: Fri, 8 Jan 1993 00:39:33 GMT
- Lines: 37
-
- harvey@opl.com (Harvey Reed) writes:
-
- >If programmers want nested functions, it sounds a lot like delegation which
- >C++ can handle quite well, as is. Just delegate to another object, or
- >your self. This leaves matters fairly explicit.
-
- Two points: firstly, I would not agree that C++ (without overloadable
- operator dot) handles delegation well; secondly, delegation can be used
- as a poor man's substitute for nested functions, but it does *not* have
- the same power/expressiveness that nested functions do. The classic
- sort of example where nested functions are useful is
-
- somefunc(lots of complex parameters) {
- lots of complex local variables;
-
- int compare(const void *ptr1, const void *ptr2) {
- const object *x = (object *)ptr1;
- const object *y = (object *)ptr2;
- // compare x and y using some complex ordering which is
- // dependant on the above parameters and local variables
- }
-
- ...
- qsort(object_array, n, sizeof(object), compare);
- ...
- }
-
- Because the interface to qsort() is fixed, the alternative is to use a rather
- ugly hack using global variables (well, ok, you can make them file-scope
- static variables rather than real global variables). Here delegation doesn't
- help.
-
- --
- Fergus Henderson fjh@munta.cs.mu.OZ.AU
- This .signature virus is a self-referential statement that is true - but
- you will only be able to consistently believe it if you copy it to your own
- .signature file!
-