home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16488 < prev    next >
Encoding:
Internet Message Format  |  1992-11-17  |  2.3 KB

  1. Path: sparky!uunet!saxony!dgil
  2. From: dgil@pa.reuter.COM (Dave Gillett)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Multiple Header Files Problem
  5. Message-ID: <1240@saxony.pa.reuter.COM>
  6. Date: 18 Nov 92 03:06:31 GMT
  7. References: <1992Nov10.164547.19059@mprgate.mpr.ca> <5189@holden.lulea.trab.se>
  8. Organization: Reuter:file Inc  (A Reuter Company) Palo Alto, CA
  9. Lines: 42
  10.  
  11. In <5189@holden.lulea.trab.se> jbn@lulea.trab.se (Johan Bengtsson) writes:
  12.  
  13. >Problem is that a.hh gets #included, #includes b.hh, which tries to
  14. >#include a.hh.  This will fail, since b.hh will not see all declarations
  15. >in a.hh (A_HH is already defined).
  16.  
  17.      If the #ifndef convention is being used, b.hh's attempt to include a.hh
  18. will include no text; many people have suggested ways in which it need not
  19. even re-open the file.  Infinite recursion or poor performance are not really
  20. the issue here.
  21.  
  22.      The "real" issue is that if b.hh really refers to information in a.hh,
  23. the compile will fail because a.hh has only partially been seen at that point.
  24. Now, how does b.hh depend on a.hh?  I can think of three scenarios:
  25.  
  26. 1. There is a member of B of type A, and a member of A of type B.
  27.       That's an infinitely recursive definition; there is no way to write
  28.       this and no way to compile it, and I doubt it would make sense if you
  29.       could.
  30.  
  31. 2. There are A methods which refer to members of B, and B methods which refer
  32.    to members of A.
  33.       The only way this can be an issue in the header files is with inline
  34.       methods.  a.hh should #include b.hh *after* the A class definition but
  35.       before the definition of inlined methods, and b.hh should do likewise.
  36.       I usually prefer to put my inlined definitions inside the class
  37.       definition, but in this case they *must* go outside.
  38.  
  39. 3. There is a member of B of type A; there are A methods which refer to 
  40.    members of B.
  41.       This is a degenerate (asymmetric) case; the same remedy as above for
  42.       case 2 will also fix this, although only one of the a.hh really needs
  43.       to do this.
  44.  
  45.      It's pretty hard to get into this fix except by making heavy use of
  46. inline methods.  Dare I suggest that anyone who regards this as a "very
  47. serious" problem is *probably* inlining too much? 
  48.  
  49.                                     Dave Gillett
  50.  
  51. [Experienced software engineer seeks Bay Area employment opportunity.
  52. Resume available on request.]
  53.