Article View: comp.std.c++
Article #1468Re: Defining members of class T within class T (_not_ recursive!)
From: Tom Payne
Date: Wed, 02 Aug 1995 18:16
Date: Wed, 02 Aug 1995 18:16
37 lines
1745 bytes
1745 bytes
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.
Tom Payne (thp@cs.ucr.edu)
Technical Details
Message-ID:
<3vofe6$3bs@galaxy.ucr.edu>Path:
arc1-ca.pugleaf.net!corvette.ucr.edu!thpReferences:
<950729200137682@wem.org>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!corvette.ucr.edu!thp From: thp@PROBLEM_WITH_INEWS_DOMAIN_FILE (Tom Payne) Newsgroups: comp.std.c++,comp.lang.c++ Subject: Re: Defining members of class T within class T (_not_ recursive!) Followup-To: comp.std.c++,comp.lang.c++ Date: 2 Aug 1995 18:16:38 GMT Organization: University of California, Riverside Department of Computer Science Distribution: world Message-ID: <3vofe6$3bs@galaxy.ucr.edu> References: <950729200137682@wem.org> NNTP-Posting-Host: corvette.ucr.edu X-Newsreader: TIN [version 1.2 PL2]