home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11275 < prev    next >
Encoding:
Text File  |  1992-07-21  |  1.1 KB  |  52 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: <1992Jul21.214406.7921@murdoch.acc.Virginia.EDU>
  6. Date: 21 Jul 92 21:44:06 GMT
  7. References: <1992Jul21.174445.24733@menudo.uh.edu>
  8. Sender: usenet@murdoch.acc.Virginia.EDU
  9. Reply-To: gs4t@virginia.edu (Gnanasekaran Swaminathan)
  10. Organization: University of Virginia
  11. Lines: 39
  12.  
  13. qincao@cs.uh.edu (Qin Cao) writes:
  14. >    I am implementing an interface with C++. I need to declare several classes
  15. > which are referenced each other in their definition. If I used pointer, then
  16. > it works fine, but I really want to use dot notation to refer the class
  17. > member, instead of "->" notation when using pointer.  ...
  18. > class X;
  19. > class Y;
  20. > class X {
  21. >   int a;
  22. >   Y b;          // if I put "Y *b;" here, it works fine 
  23. > };
  24. > class Y {
  25. >  int c;
  26. >  X d;
  27. > };
  28.  
  29. Please use references. I just tested the following in
  30. the GNU C++ compiler.
  31.  
  32. class X;
  33.  
  34. class Y {
  35.     X& x;
  36. public:
  37.     Y();
  38. };
  39.  
  40. class X {
  41.     Y y;
  42. public:
  43.     X() {}
  44. };
  45.  
  46. Y::Y(): x(*new X) {}
  47.  
  48. -Sekar
  49.