home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!rational.com!thor!rmartin
- From: rmartin@thor.Rational.COM (Bob Martin)
- Subject: Re: Multiple Header Files Problem
- Message-ID: <rmartin.721531576@thor>
- Sender: news@rational.com
- Organization: Rational
- References: <rmartin.721359424@thor> <1992Nov10.104447.12882@us-es.sel.de> <rmartin.721442494@thor> <1drjpsINN1jr@alnitak.usc.edu>
- Date: Thu, 12 Nov 1992 01:26:16 GMT
- Lines: 51
-
- coller@alnitak.usc.edu (Lee D. Coller) writes:
-
- |In article <rmartin.721442494@thor> rmartin@thor.Rational.COM (Bob Martin) writes:
- |>
- |>What I had not realized, until you (and many others) pointed it out to
- |>me, is that the #ifndef convention breaks inclusion cycles. Of course
- |>it does.
- |>
-
- |Actually it doesn't entirely solve the circular dependency problem.
- |Consider two files, file a.h containing:
-
- |#ifndef a_h
- |#define a_h
-
- |#include "b.h"
-
- |class a {
- |public:
- | b* _b;
- | void do_b_fnc() { _b->b_fnc(); }
- | void a_fnc();
- |};
- |#endif
-
- |File b.h contains:
-
- |#ifndef b_h
- |#define b_h
-
- |#include "a.h"
-
- |class b {
- |public:
- | a* _a;
- | void do_a_fnc() { _a->a_fnc(); }
- | void b_fnc();
- |};
- |#endif
-
- This is an excellent example of the dangers of inline functions. In
- this case, the reason that class a or b cannot be forward declared is
- because of the inline functions. If the inlines are removed, then
- both classes could be forward delcared and the cycle could be broken.
-
-
- --
- Robert Martin Training courses offered in:
- R. C. M. Consulting Object Oriented Analysis
- 2080 Cranbrook Rd. Object Oriented Design
- Green Oaks, Il 60048 (708) 918-1004 C++
-