Article View: comp.std.c++
Article #1469Re: Defining members of class T within class T (_not_ recursive!)
From: Henry Baker
Date: Thu, 03 Aug 1995 00:42
Date: Thu, 03 Aug 1995 00:42
44 lines
1987 bytes
1987 bytes
In article <3vofe6$3bs@galaxy.ucr.edu>, thp@PROBLEM_WITH_INEWS_DOMAIN_FILE
(Tom Payne) wrote:
> Henry Baker (henry.baker@wem.org) wrote:
> : Suppose I have the following nested class:
>
> : struct pair
> : {struct pair_rep
> : {pair car,cdr;}; // inner class has member of outer class.
> : pair_rep *rep;};
>
> : I understand the rule saying that a class cannot be a member of itself
> : [Stroustrup#2, page 545] (Bertrand Russell is now spinning in his grave ;-),
> : but I'm having trouble understanding why a _nested_ class cannot have a
> : member
> : of the outer class being defined. This is especially irritating, since the
> : above is capable of being rewritten as [Stroustrup#2, page 645]:
>
> : struct pair
> : {struct pair_rep;
> : pair_rep *rep;};
>
> : struct pair::pair_rep
> : {pair car,cdr;};
>
> : Are compiler writers just being lazy, or what??
>
>
> It appears that the struct type pair is not yet defined at the point
> where it is used to delcare car and cdr. (Note that sizeof(pair) will
> not be known for another two lines.)
>
> In the revised version, when the struct type pair is used to declare
> car and cdr, it is already known that pairs consist of a single member
> called rep, which points to a structure of a thus-far undefined type
> called pair_rep.
So should I put down your vote in the 'lazy compiler writers' column?
I didn't hear any good reasons for not accepting the code as originally
written.
--
www/ftp directory:
ftp://ftp.netcom.com/pub/hb/hbaker/home.html
Technical Details
Message-ID:
<hbaker-0208951642250001@192.0.2.1>Path:
arc1-ca.pugleaf.net!netcom.com!NewsWatcher!userReferences:
<950729200137682@wem.org> <3vofe6$3bs@galaxy.ucr.edu>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 class T (_not_ recursive!) Message-ID: <hbaker-0208951642250001@192.0.2.1> Sender: hbaker@netcom19.netcom.com Organization: nil organization References: <950729200137682@wem.org> <3vofe6$3bs@galaxy.ucr.edu> Date: Thu, 3 Aug 1995 00:42:25 GMT