home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11384 < prev    next >
Encoding:
Internet Message Format  |  1992-07-22  |  1.2 KB

  1. Path: sparky!uunet!pmafire!news.dell.com!swrinde!mips!pacbell.com!decwrl!netcomsv!delfin.com!hades!kinne
  2. From: kinne@delfin.com (Kinne Strong)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: classes referenced each in their declaration
  5. Message-ID: <1992Jul22.222036.27498@delfin.com>
  6. Date: 22 Jul 92 22:20:36 GMT
  7. References: <1992Jul21.214406.7921@murdoch.acc.Virginia.EDU>
  8. Sender: news@delfin.com (USENET on Delfin)
  9. Reply-To: kinne@netcom.com
  10. Organization: Foxglove Associates
  11. Lines: 36
  12. Nntp-Posting-Host: hades
  13. X-Newsreader: Tin 1.1 PL4
  14.  
  15. gs4t@virginia.edu (Gnanasekaran Swaminathan) writes:
  16. : Please use references. I just tested the following in
  17. : the GNU C++ compiler.
  18. : class X;
  19. : class Y {
  20. :     X& x;
  21. : public:
  22. :     Y();
  23. : };
  24. : class X {
  25. :     Y y;
  26. : public:
  27. :     X() {}
  28. : };
  29. : Y::Y(): x(*new X) {}
  30.  
  31. It compiled. Did you try to make an X or a Y? I did. It used up all
  32. available swap space and died. That's still an infinite object.
  33.  
  34. If you say
  35.  
  36.     Y big;
  37.  
  38. the space for the first Y is allocated on the stack. It needs an X, so
  39. it does a new X, which allocates space for the second Y, which also
  40. needs an X, so it does a new X, which allocates space for the third Y,
  41. which also needs an X, so ...
  42.  
  43. --
  44. Kinne Strong
  45. kinne@netcom.com
  46.