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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!newsgate.watson.ibm.com!yktnews!admin!siena!mittle
  3. From: mittle@watson.ibm.com (Josh Mittleman)
  4. Subject: Re: classes referenced each in their declaration
  5. Sender: news@watson.ibm.com (NNTP News Poster)
  6. Message-ID: <1992Jul21.192039.5252@watson.ibm.com>
  7. Date: Tue, 21 Jul 1992 19:20:39 GMT
  8. Distribution: na
  9. Disclaimer: This posting represents the poster's views, not necessarily those of IBM
  10. References:  <1992Jul21.174445.24733@menudo.uh.edu>
  11. Nntp-Posting-Host: siena.watson.ibm.com
  12. Organization: IBM T.J. Watson Research Center
  13. Lines: 26
  14.  
  15. qincao@cs.uh.edu (Qin Cao) writes:
  16.  
  17. > I need to declare several classes which are referenced each other in
  18. > their defination. If I used pointer, then it works fine, but I realy want
  19. > to use dot notation to refer the class member, instead of "->" notation
  20. > when using pointer. Unfortunately without using pointer, the C++ compiler
  21. > does not buy that, it gave a error message...
  22.  
  23. Use references:
  24.  
  25. class Y;
  26.  
  27. class X {
  28.   Y& b;
  29. };
  30.  
  31. class Y {
  32.  X& d;
  33. };
  34.  
  35. You must initialize X::b in every constructor for X and Y::d in every
  36. constructor for Y, but otherwise everything should work just fine.  
  37.  
  38. ===========================================================================
  39. Josh Mittleman (mittle@watson.ibm.com)
  40. J2-C28 T.J. Watson Research Center, PO Box 704, Yorktown Heights, NY  10598
  41.