From 3790260791263350744
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 109fba,ac06fef48c3c04df
X-Google-Attributes: gid109fba,public
X-Google-Thread: f78e5,ac06fef48c3c04df
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 1995-01-24 15:29:28 PST
Path: nntp.gmd.de!newsserver.jvnc.net!nntpserver.pppl.gov!princeton!udel!news.mathworks.com!hookup!news.moneng.mei.com!sol.ctr.columbia.edu!news.cs.columbia.edu!news.cs.columbia.edu!fenster
From: fenster@ground.cs.columbia.edu (Sam Fenster)
Newsgroups: comp.lang.c++,comp.std.c++
Subject: Re: friends and local classes
Date: 24 Jan 1995 23:29:28 GMT
Organization: Columbia University Department of Computer Science
Lines: 28
Message-ID: <FENSTER.95Jan24182929@ground.cs.columbia.edu>
References: <3frgln$deh@senator-bedfellow.MIT.EDU> <3froli$gss@news.panix.com>
	<3fskgs$qsg@engnews2.Eng.Sun.COM> <JGEALOW.95Jan22230221@mtl.mit.edu>
	<3g0kgm$gue@engnews2.Eng.Sun.COM>
NNTP-Posting-Host: ground.cs.columbia.edu
In-reply-to: clamage@Eng.Sun.COM's message of 23 Jan 1995 16:12:06 GMT
Xref: nntp.gmd.de comp.lang.c++:87956 comp.std.c++:11251


clamage@Eng.Sun.COM (Steve Clamage) writes:

> Who said local classes are a good idea? I think they are pointless.[...]  A
> number of people on the C++ Committee would like to eliminate member
> functions from local classes (myself included), although I don't expect that
> to happen.

Let's say you want to guarantee that some action takes place when a function
exits, regardless of whether it's by any of a number of return statements,
falling off the end, or because of an exception.  The only way is to create a
local object with a destructor that performs the action.  That destructor must
have the function's local variables in its scope:

     void f () {
        // ...
        class On_Exit {~On_Exit() {delete foo; close(bar); baz--;};} on_exit;
        // ...
     }

When Bjarne made "int i;" an executable statement so it could be put anywhere
in a block, his rationale was that things should be declared where they are
used.  The same goes for a class that is created for a local purpose.  And
such classes must be allowed to have member functions.

Ideally, we'd have local functions too, for similar reasons (e.g. a comparison
function to pass to "qsort").  I don't expect that soon.  But let's not get
rid of local classes, OK?


