🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Defining members of class T within cla

#1640
From: Steve Clamage
Date: Mon, 07 Aug 1995 15:33
44 lines
2204 bytes
In article 0608952350520001@192.0.2.1, hbaker@netcom.com (Henry Baker) writes:
>In article <401l3v$eri@engnews2.Eng.Sun.COM>, clamage@Eng.Sun.COM (Steve
>Clamage) wrote:
>
>> >class pair
>> >{class pair_rep {pair car,cdr;};
>> > pair_rep *rep;};                // Only needs to know sizeof(pointer).
>> 
>> Class pair_rep has members of type pair, but type pair is not a
>> complete type at that point in the source code. The problem is not
>> the pointer to pair_rep, but the definition of pair_rep itself.
>> 
>> Another example, without any cross-referencing:
>> 
>> class A;
>> 
>> class B {
>>     A a; // invalid, since A is not a complete type
>> };
>> 
>> 
>> It doesn't matter whether you use class B or not. Its definition
>> is invalid. The definition of class B must appear after that of
>> class A, or be removed entirely. In your example, you have to define
>> the nested class pair_rep after the definition of pair, not inside it.
>
>But what about the ANSI/ISO resolution, 9.7, page 421:
>
>"Like a member function, a nested class may be declared within the
>enclosing class and defined elsewhere in the same or containing scope,
>using the qualified name for the class definition:..."
>
>One might reasonably infer that 'like a member function' implied that the same
>sort of 'rewriting equivalence' exists for nested classes as well as member
>function bodies.

No, you cannot make that inference, and that is not what was intended
anyway. The difference is that in order to instantiate a class, you
do not need to know anything about the contents of its member functions.
You DO need to know everything about the types of its members, however.
Thus, members of a class may not have incomplete types.

---
Steve Clamage, stephen.clamage@eng.sun.com
Technical Details
Message-ID: <405boq$4br@engnews2.Eng.Sun.COM>
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!usenet
References: <hbaker-0608952350520001@192.0.2.1>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!usenet
From: clamage@Eng.Sun.COM (Steve Clamage)
Newsgroups: comp.std.c++
Subject: Re: Defining members of class T within cla
Date: 7 Aug 1995 15:33:46 GMT
Organization: Sun Microsystems Inc.
Message-ID: <405boq$4br@engnews2.Eng.Sun.COM>
References: <hbaker-0608952350520001@192.0.2.1>
Reply-To: clamage@Eng.Sun.COM
NNTP-Posting-Host: taumet.eng.sun.com