🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1478

Re: Defining members of class T within cla

#1478
From: Henry Baker
Date: Sat, 05 Aug 1995 18:07
60 lines
3121 bytes
In article <3vthqo$m5t@engnews2.Eng.Sun.COM>, clamage@Eng.Sun.COM wrote:

> In article pci@galaxy.ucr.edu, thp@PROBLEM_WITH_INEWS_DOMAIN_FILE (Tom
Payne) writes:
> >
> >I'm voting "overworked compiler writers."  
> >
> >C++ does not use C's single-pass semantics for names occurring within
> >a class.  Specifically, the C++ "reconsideration rule" states:
> >
> >   A name used in a class S must refer to the same declaration when
> >   reevaluated in its context and in the completed scope of S, which
> >   consists of the class S, S's base classes, and all classes enclosing
> >   S.  [D&E, p.142]
> 
> The reconsideration rule requires at most two passes over a class, and a
> second pass generally makes other things easier to deal with anyway.

I don't fully understand 'reconsideration', but I don't think that it
is pertinent to this particular problem.

> Allowing use of an incomplete type, on the other hand, could require an
> arbitrary number of passes. The original example required postponing
> processing of a member type until the outer type was complete. This
> postponement could be required in principle to any number of levels.

The ARM says the following [9.2]:

"Members that are class objects must be objects of previously declared
classes.  In particular, a class cl may not _contain_ an object of class
cl, but it may _contain_ a _pointer_ or _reference_ to an object of class cl."

So, since the structure I was defining did not 'contain' a member of the
class being defined, but _does_ 'contain' a pointer to an object of the
class being defined, it meets all of the requirements of the ARM.  The
ARM wording makes no exception for lazy or unimaginative compiler
writers.  There is also no discussion whatsover about 'incomplete'
types, since all types are complete at the appropriate places.

> There is no difficulty in providing the definitions in the
> correct order, and I would argue that the resulting code is easier
> to read anyway. (You are entitled to a different opinion, of course.)

This is a little like asking the person providing information to a
sort routine to guarantee that the information is already in sorted
order, so that the sort routine only has to _check_ the order, but never
has to sort it.  I think that the whole _point_ of a compiler is to
handle the reorganization of information of this sort.

If I recall correctly, the program went something like this:

class pair
{class pair_rep {pair car,cdr;};
 pair_rep *rep;};                // Only needs to know sizeof(pointer).

As far as I can tell, all of the ARM requirements are met.

-- 
www/ftp directory:
ftp://ftp.netcom.com/pub/hb/hbaker/home.html
Technical Details
Message-ID: <hbaker-0508951007050001@192.0.2.1>
Path: arc1-ca.pugleaf.net!netcom.com!NewsWatcher!user
References: <3vrcu8$pci@galaxy.ucr.edu> <3vthqo$m5t@engnews2.Eng.Sun.COM>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++,comp.lang.c++
Path: arc1-ca.pugleaf.net!netcom.com!NewsWatcher!user
From: hbaker@netcom.com (Henry Baker)
Subject: Re: Defining members of class T within cla
Message-ID: <hbaker-0508951007050001@192.0.2.1>
Sender: hbaker@netcom23.netcom.com
Organization: nil organization
References: <3vrcu8$pci@galaxy.ucr.edu> <3vthqo$m5t@engnews2.Eng.Sun.COM>
Date: Sat, 5 Aug 1995 18:07:05 GMT