home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 15855 < prev    next >
Encoding:
Text File  |  1992-11-07  |  1.1 KB  |  45 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!well!donovan
  3. From: donovan@well.sf.ca.us (Sean Donovan)
  4. Subject: Re: Multiple Header Files Problem
  5. Message-ID: <BxAA12.2Cz@well.sf.ca.us>
  6. Sender: news@well.sf.ca.us
  7. Organization: Whole Earth 'Lectronic Link
  8. References: <1992Nov3.113121.3388@ntuix.ntu.ac.sg>
  9. Date: Fri, 6 Nov 1992 07:27:01 GMT
  10. Lines: 33
  11.  
  12. In article <1992Nov3.113121.3388@ntuix.ntu.ac.sg> gthkoh@ntuix.ntu.ac.sg (Koh Thong Hwee) writes:
  13.  
  14. > [define class B which references class A which references class B]
  15.  
  16. In C++ you can specify a forward reference to a class by just saying:
  17.  
  18. class <class-name>;
  19.  
  20. In that header module you can then declare a member variable to that class.
  21.  
  22. Ex:
  23.  
  24. class A;
  25.  
  26. class B {
  27. private:
  28.    class A *foo;
  29. };
  30.  
  31. then go on to define your cyclic relation:
  32.  
  33. class A {
  34. private:
  35.     class B *bar;
  36. };
  37.  
  38. This should solve your problem.  You also want to be careful about using
  39. inline funcitons within your class definitions.  If you reference a member
  40. function of class A when you define an inline function within class B you
  41. will run into trouble because class A has not been defined yet.
  42.  
  43.  
  44. Sean Donovan
  45.