From 4355602646873888741
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,a69618ea97f65037
X-Google-Attributes: gidf78e5,public
From: David R Tribble <david.tribble@noSPAM.central.beasys.com>
Subject: Re: nested functions
Date: 1998/04/29
Message-ID: <35461A7F.4A92@noSPAM.central.beasys.com>#1/1
X-Deja-AN: 348618725
Approved: Fergus Henderson <fjh@cs.mu.oz.au>
Content-Transfer-Encoding: 7bit
References: <6hac23$8lb$1@news2.isdnet.net> <353b85b9.0@news.iprolink.ch> <sfn2dcncm2.fsf@bidra168.bbn.hp.com> <35459993.3BC581B0@physik.tu-muenchen.de>
X-Original-Date: Tue, 28 Apr 1998 13:05:51 -0500
Mime-Version: 1.0
Reply-To: david.tribble@noSPAM.central.beasys.com
Content-Type: text/plain; charset=us-ascii
Organization: BEA Systems, Inc.
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUANUaZQuEDnX0m9pzZAQH3QQF/XO/f19CZBSQtwe+JFixz5kFRpSJLSRYr fYgizvs7IUay9hgrsurooq8VckUJcmyg =kIzF
Newsgroups: comp.std.c++


Christopher Eltschka wrote:
> Closures might be useful, but have too complicated interaction
> with the C++ object model (I guess they would work well with the
> Java object model). Note however, that once you return from the
> enclosing function, a closure is in no way different from a function
> object, from the user's point of view. And before the return, they
> are not any different to ordinary nested functions. Indeed I guess
> I would never use them at all.
> 
> However, I'd still like to see nested functions in C++. While
> they are not a tool you use everyday, they are very handy in
> some situations, and they don't cause any problems with the C++
> object model.

One benefit of nested functions that I haven't seen mentioned is
that they act a lot like private member functions but they don't
need to be declared in the class declaration.  For programmers (like
me) who believe it's sinful to show off class private members in
header files (to client functions that have no business seeing the
class's privates), this is a good thing.

A function nested within a normal (non-static) member function
acts like a file-static function as far as scoping, but still has
access to all the class members like a true private member
function does.

Not that I'm in favor of adding nested functions to C++, mind you.
I'd rather see a way of declaring private member functions within
a source file that didn't require adding a function declaration to
the class header file.  This would accomplish the same thing for me.

In fact, it would be nice if I could somehow put only the public
members in the class declaration in the (distributed) header file,
and extend the declaration by adding the protected and private
member declarations in a local (undistributed) header file.
Now that would be true data hiding.

-- David R. Tribble, david.tribble@noSPAM.central.beasys.com --
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]



