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