home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 16120 < prev    next >
Encoding:
Internet Message Format  |  1992-11-11  |  1012 b 

  1. Path: sparky!uunet!think.com!ames!agate!darkstar.UCSC.EDU!cats.ucsc.edu!flynn
  2. From: flynn@cats.ucsc.edu (Eric Alan Flynn)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Multiple Header Files Problem
  5. Date: 11 Nov 1992 22:06:37 GMT
  6. Organization: University of California; Santa Cruz
  7. Lines: 33
  8. Distribution: world
  9. Message-ID: <1ds05dINN8em@darkstar.UCSC.EDU>
  10. References: <1992Nov3.113121.3388@ntuix.ntu.ac.sg>
  11. NNTP-Posting-Host: am.ucsc.edu
  12.  
  13. (message paraphrased) why won't this work?
  14. add the following line
  15. class B;
  16. This creates a forward declaration of the class B.
  17.  
  18. >class A
  19. >{
  20. >public
  21. >   B* pB;
  22. >   void foo();
  23. >};
  24. >void A::foo()
  25. >{   
  26. >   pB = new B(this);
  27. >}
  28. >class B
  29. >{
  30. >public
  31. >   A* pParentA;
  32. >   inline B(A* pA) {pParentA = pA};
  33. };
  34.  
  35. Note that the only thing you can do is use B to create a B* pointer,
  36. so if you want to members of A to access _methods_ of B,
  37.  you will have to declare those methods of A out of
  38. line, after the delcaration of the class B.
  39.  
  40. Hope this helps,
  41.  
  42. Eric
  43.  
  44. >TH Koh
  45. >gthkoh@ntuix.ntu.ac.sg
  46.