Article View: comp.std.c++
Article #1479Re: Defining members of class T within cla
From: Steve Clamage
Date: Sun, 06 Aug 1995 05:48
Date: Sun, 06 Aug 1995 05:48
30 lines
1492 bytes
1492 bytes
hbaker@netcom.com (Henry Baker) writes:
>So, since the structure I was defining did not 'contain' a member of the
>class being defined,
Yes it did. The inner struct had a member of an incomplete type.
>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.
--
Steve Clamage, stephen.clamage@eng.sun.com
Technical Details
Message-ID:
<401l3v$eri@engnews2.Eng.Sun.COM>Path:
arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!clamageReferences:
<3vrcu8$pci@galaxy.ucr.edu> <3vthqo$m5t@engnews2.Eng.Sun.COM> <hbaker-0508951007050001@192.0.2.1>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!clamage From: clamage@Eng.Sun.COM (Steve Clamage) Newsgroups: comp.std.c++,comp.lang.c++ Subject: Re: Defining members of class T within cla Date: 6 Aug 1995 05:48:47 GMT Organization: Sun Microsystems Inc., Mountain View, CA Message-ID: <401l3v$eri@engnews2.Eng.Sun.COM> References: <3vrcu8$pci@galaxy.ucr.edu> <3vthqo$m5t@engnews2.Eng.Sun.COM> <hbaker-0508951007050001@192.0.2.1> NNTP-Posting-Host: taumet2.eng.sun.com X-Newsreader: NN version 6.5.0 #21 (NOV)