From 6045309038416351559
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,fb1a92fa405c930c
X-Google-Attributes: gidf78e5,public
From: David R Tribble <dtribble@technologist.com>
Subject: Re: nested functions
Date: 1999/06/23
Message-ID: <376685B7.AA13A046@technologist.com>#1/1
X-Deja-AN: 492912512
Content-Transfer-Encoding: 7bit
Approved: Valentin Bonnard <bonnard@clipper.ens.fr>
References: <7jd4c5$nup$1@nnrp1.deja.com> <7jjjr6$r02$1@nnrp1.deja.com> <7jma5c$i85@abyss.West.Sun.COM> <37dd56e1.565652003@nntp.ix.netcom.com> <lz%73.9759$wk2.183779@newscene.newscene.com> <7jro7p$ntt$1@nnrp1.deja.com> <_xh83.25803$wk2.383242@newscene.newscene.com> <082d72743190c69CPIMSSMTPU07@email.msn.com> <7jvh45$5ms$1@engnews1.eng.sun.com>
X-Original-Date: Tue, 15 Jun 1999 11:56:23 -0500
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
Organization: Member of the Vast Right-Wing Conspiracy
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUAN3DNf6wEuYhIxRhxAQF9EwH/cu5TWHhIKyiFI6mLC2e/EXz6e8RslCNN Q8nY/kKcmCBWeDYhnks+7eH2RUdS6ZbGdunMw5386cEXYbBo81/SOw== =tOCa
Mime-Version: 1.0
Newsgroups: comp.std.c++

Steve Clamage wrote:
> Maybe you could explain how local functions that could not be
> called from outside the enclosing function scope would be a
> useful addition to C++. What programming problems can be solved
> more easily? It seems to me that a class with member functions
> solves all the same problems, and does a better job of it.

It would be useful for adding local (i.e., externally hidden)
functions to a class that have full access to all the class's
members (by having access to their outer function's 'this' pointer)
without the need for adding their declarations to the class
declaration.  Sort of like being able to define static functions
in a source file that act like member functions (by having access
to all the members of the class) without needing to be declared in
the class declaration (and are thus hidden to casual readers of
the class's header file).  This would make it easier to hide the
private implementation details of a class without revealing the
names of of its private member functions in its declaration.

Granted, this isn't a big win, and we usually aren't saving any
effort in the long run by avoiding the extra member function
declarations.

I think the effort of adding local functions to C++ outweighs
their benefits.  Since I began programming in C/C++ in 1982, I
have had the need for something resembling nested functions
perhaps two or three times, and I was always able to find a
reasonable existing alternative.

-- David R. Tribble, dtribble@technologist.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              ]



