home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!pmafire!news.dell.com!swrinde!mips!pacbell.com!decwrl!netcomsv!delfin.com!hades!kinne
- From: kinne@delfin.com (Kinne Strong)
- Newsgroups: comp.lang.c++
- Subject: Re: classes referenced each in their declaration
- Message-ID: <1992Jul22.222036.27498@delfin.com>
- Date: 22 Jul 92 22:20:36 GMT
- References: <1992Jul21.214406.7921@murdoch.acc.Virginia.EDU>
- Sender: news@delfin.com (USENET on Delfin)
- Reply-To: kinne@netcom.com
- Organization: Foxglove Associates
- Lines: 36
- Nntp-Posting-Host: hades
- X-Newsreader: Tin 1.1 PL4
-
- gs4t@virginia.edu (Gnanasekaran Swaminathan) writes:
- :
- : Please use references. I just tested the following in
- : the GNU C++ compiler.
- :
- : class X;
- :
- : class Y {
- : X& x;
- : public:
- : Y();
- : };
- :
- : class X {
- : Y y;
- : public:
- : X() {}
- : };
- :
- : Y::Y(): x(*new X) {}
-
- It compiled. Did you try to make an X or a Y? I did. It used up all
- available swap space and died. That's still an infinite object.
-
- If you say
-
- Y big;
-
- the space for the first Y is allocated on the stack. It needs an X, so
- it does a new X, which allocates space for the second Y, which also
- needs an X, so it does a new X, which allocates space for the third Y,
- which also needs an X, so ...
-
- --
- Kinne Strong
- kinne@netcom.com
-