home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!dtix!darwin.sura.net!uvaarpa!murdoch!virginia.edu!gs4t
- From: gs4t@virginia.edu (Gnanasekaran Swaminathan)
- Newsgroups: comp.lang.c++
- Subject: Re: classes referenced each in their declaration
- Message-ID: <1992Jul23.003724.13021@murdoch.acc.Virginia.EDU>
- Date: 23 Jul 92 00:37:24 GMT
- References: <1992Jul21.214406.7921@virginia.edu> <1992Jul22.222036.27498@delfin.com>
- Sender: usenet@murdoch.acc.Virginia.EDU
- Reply-To: gs4t@virginia.edu (Gnanasekaran Swaminathan)
- Organization: University of Virginia
- Lines: 38
-
- kinne@delfin.com (Kinne Strong) writes:
- > 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 ...
-
- Thanks for catching the bug. The following is tested
- in GNU C++ and it works.
-
- class Y;
-
- class X {
- Y& y;
- public:
- X(const Y& y1): y(y1) {}
- };
-
- class Y {
- X x;
- public:
- Y(): x(*this) {}
- Y(const Y& y): x(y) {}
- };
-
- main ()
- {
- Y y1;
- Y y2 = y1;
- X x1(y1);
- X x2(y2);
- }
-