home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11386 < prev    next >
Encoding:
Text File  |  1992-07-22  |  1.2 KB  |  51 lines

  1. Path: sparky!uunet!dtix!darwin.sura.net!uvaarpa!murdoch!virginia.edu!gs4t
  2. From: gs4t@virginia.edu (Gnanasekaran Swaminathan)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: classes referenced each in their declaration
  5. Message-ID: <1992Jul23.003724.13021@murdoch.acc.Virginia.EDU>
  6. Date: 23 Jul 92 00:37:24 GMT
  7. References: <1992Jul21.214406.7921@virginia.edu> <1992Jul22.222036.27498@delfin.com>
  8. Sender: usenet@murdoch.acc.Virginia.EDU
  9. Reply-To: gs4t@virginia.edu (Gnanasekaran Swaminathan)
  10. Organization: University of Virginia
  11. Lines: 38
  12.  
  13. kinne@delfin.com (Kinne Strong) writes:
  14. > It compiled. Did you try to make an X or a Y? I did. It used up all
  15. > available swap space and died. That's still an infinite object.
  16. > If you say
  17. >     Y big;
  18. > the space for the first Y is allocated on the stack. It needs an X, so
  19. > it does a new X, which allocates space for the second Y, which also
  20. > needs an X, so it does a new X, which allocates space for the third Y,
  21. > which also needs an X, so ...
  22.  
  23. Thanks for catching the bug. The following is tested
  24. in GNU C++ and it works.
  25.  
  26. class Y;
  27.  
  28. class X {
  29.     Y&    y;
  30.     public:
  31.     X(const Y& y1): y(y1) {}
  32. };
  33.  
  34. class Y {
  35.     X    x;
  36.     public:
  37.     Y(): x(*this) {}
  38.     Y(const Y& y): x(y) {}
  39. };
  40.  
  41. main ()
  42. {
  43.     Y y1;
  44.     Y y2 = y1;
  45.     X x1(y1);
  46.     X x2(y2);
  47. }
  48.