From 3867667611266131186
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-27 18:01:50 PST
Newsgroups: comp.lang.c++,comp.std.c++
Path: nntp.gmd.de!newsserver.jvnc.net!howland.reston.ans.net!pipex!uunet!news.cygnus.com!news!jason
From: jason@cygnus.com (Jason Merrill)
Subject: Re: friends and local classes
In-Reply-To: andrewfg@dai.ed.ac.uk's message of Fri, 27 Jan 1995 10:26:33 GMT
Content-Type: text/plain; charset=US-ASCII
Message-ID: <JASON.95Jan27180150@phydeaux.cygnus.com>
Followup-To: comp.lang.c++,comp.std.c++
Sender: news@cygnus.com
Nntp-Posting-Host: phydeaux.cygnus.com
Organization: Cygnus Support, Mountain View, CA
References: <FENSTER.95Jan24182929@ground.cs.columbia.edu> <3g5qc6$16p@news.cc.utah.edu>
	<3g5rei$dl8@news.panix.com> <D327o9.7At@aisb.ed.ac.uk>
Mime-Version: 1.0
Date: Sat, 28 Jan 1995 02:01:50 GMT
Lines: 35
Xref: nntp.gmd.de comp.lang.c++:88263 comp.std.c++:11267

>>>>> Andrew Fitzgibbon <andrewfg@dai.ed.ac.uk> writes:

> swillden@fcom.cc.utah.edu (Shawn Willden) wrote:
>> 
>> Sam Fenster (fenster@ground.cs.columbia.edu) wrote:
>> : 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?
>> 
>> Just make a local class with a static function if you need a local function.
>> [paraphrasing:]
>> void functionWithLocalFunction() {
>> struct Local {
>> int static compare(const void* a, const void* b)
>> {...}
>> };
>> qsort(array, sizeof(array)/sizeof(array[0]), sizeof(array),
>> &Local::compare);

> That's not a local function.  It doesn't have lexically scoped access to
> the surrounding function's variables.  It is as hard to implement this
> properly as it is to implement proper local functions.

Actually, it does have lexically scoped access to the surrounding
function's variables.  It's just that using an auto variable or a parameter
is ill-formed.

> I expect that just after GNU pascal comes out G++ will support local
> functions ... Jason? :)

Well, GNU C already supports nested functions, so it doesn't need to wait
for GNU pascal.  It just needs to wait for someone to implement it (which
may be happening).

Jason


